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

Not able to start when add next-logger #6

Closed
dkleber89 opened this issue Sep 21, 2021 · 7 comments
Closed

Not able to start when add next-logger #6

dkleber89 opened this issue Sep 21, 2021 · 7 comments

Comments

@dkleber89
Copy link

When i add next-logger to my Project im not able to start nextjs anymore:

> cross-env NODE_OPTIONS='-r next-logger' next start

Der Befehl "next-logger" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
events.js:352
      throw er; // Unhandled 'error' event
      ^

Error: spawn next-logger ENOENT
    at notFoundError (C:\Projekte\Mobility.Portal.Web\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Projekte\Mobility.Portal.Web\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Projekte\Mobility.Portal.Web\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess.cp.emit (C:\Projekte\Mobility.Portal.Web\node_modules\cross-spawn\lib\enoent.js:30:37)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn next-logger',
  path: 'next-logger',
  spawnargs: [ 'next', 'start' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mobility.portal.web@1.0.0 start: `cross-env NODE_OPTIONS='-r next-logger' next start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mobility.portal.web@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Projekte\_npm\_logs\2021-09-21T07_33_23_675Z-debug.log

Used Versions:
"next": "^11.1.2",
"next-logger": "^2.1.1",

OS:
Windows for dev and later Alpine Linux Kubernetes Container

What do im wrong?

@dkleber89
Copy link
Author

When i use the same in Alpine Linux Container it works like expected

@atkinchris
Copy link
Collaborator

Thanks for raising this - I don't develop natively on Windows (always through WSL or macOS), so I hadn't run into it before.

To rule out interference from cross-env or cross-spawn, please can you see if the following works for you as a test?

set NODE_OPTIONS="-r next-logger"

npx next start
# ...or whichever script you have aliases to "next start"
# e.g. npm run start

@dkleber89
Copy link
Author

When i set NODE_OPTIONS directly then it works as expected.

Maybe there is a Problem with cross-env ... but can´t find out what it is ... the other env variables working fine with the cross-env

@cahaseler
Copy link

cahaseler commented Nov 16, 2021

I'm also interested in using this to develop on Windows without having to ask my team to manually set config vars. Happy to help test if you have ideas.

@atkinchris
Copy link
Collaborator

@cahaseler - the library needs to be loaded into the Node environment before any other code, including Next.js. The fastest way is to use NODE_OPTIONS to require a module into the environment before starting Next.js' CLI - and environment variables are needed for this.

Alternatively, you could write a tiny script that requires next-logger and then the Next.js' CLI - and then run this, instead of the Next.js CLI. For example:

require('next-logger')
require('next/dist/bin/next')
node next.js

@laggingreflex
Copy link

laggingreflex commented Nov 22, 2021

This seems to be an issue with cross-env: #143, #248.

PS: I've just fixed this in my library laggingreflex/win-node-env#8 which is an alternative to cross-env.

@atkinchris
Copy link
Collaborator

I'm going to close this, as an issue with cross-env. If it turns out to be this library, please re-open this.

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

4 participants