Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware doesn't load relative to where you run the CLI from #245

Open
1j01 opened this issue Mar 20, 2018 · 4 comments
Open

Middleware doesn't load relative to where you run the CLI from #245

1j01 opened this issue Mar 20, 2018 · 4 comments

Comments

@1j01
Copy link

1j01 commented Mar 20, 2018

Issue description

If I try to use the --middleware option with a relative path, it fails, and it doesn't give much information.
(It's hard to tell where it's searching from; it's buried in the middle of a stack trace.)

Error: Cannot find module 'extensionless-urls.js'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at /home/ubuntu/workspace/node_modules/live-server/index.js:174:10
    at Array.map (native)
    at Object.LiveServer.start (/home/ubuntu/workspace/node_modules/live-server/index.js:168:13)
    at Object.<anonymous> (/home/ubuntu/workspace/node_modules/live-server/live-server.js:166:12)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

I had to add ../../ to the --middleware option to get it to work, which is ugly. It seems like it should really look for files relative to where you launch the CLI from, i.e. the current working directory of the process.

Software details

  • Command line used for launching live-server: live-server --middleware=extensionless-urls.js
  • OS: Linux
  • Browser (if browser related):
  • Node.js version: v9.5.0
  • live-server version: 1.2.0
@rasmniel
Copy link

I've also been struggling with this issue.

The problem is especially prominent when running live-server through npx, in which case it is basically impossible to use non-builtin middleware without supplying an absolute path to the middleware file (which is undesirable as it is unlikely to work across different machines)

I'm setting up a small dev environment for our frontenders, and this is not possible without explicitly installing live-server in the project in order to supply the necessary middleware.

@1j01
Copy link
Author

1j01 commented Oct 18, 2019

@rasmniel If you're including middleware for live-server in the project, what's wrong with installing live-server in the project (as a dev dependency)?

@rasmniel
Copy link

Since my middleware is generic connect middleware, it could be used with any connect-compatible setup, e.g. express. This is why I don't want to explicitly add live-server.

Adding the dependency would be a workaround rather than a fix, which seems kinda half-hearted to me. There's so much "out-of-the-box" utility in this little package. Why not make it go a bit further with more reliable path resolution?

@rasmniel
Copy link

rasmniel commented Oct 23, 2019

I've made a pull request to remedy this problem #330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants