How do I debug “Error: spawn ENOENT” on node.js?

后端 未结 25 2741
轻奢々
轻奢々 2020-11-22 03:00

When I get the following error:

events.js:72
        throw er; // Unhandled \'error\' event
              ^
Error: spawn ENOENT
    at errnoException (chil         


        
25条回答
  •  后悔当初
    2020-11-22 03:28

    Are you changing the env option?

    Then look at this answer.


    I was trying to spawn a node process and TIL that you should spread the existing environment variables when you spawn else you'll loose the PATH environment variable and possibly other important ones.

    This was the fix for me:

    const nodeProcess = spawn('node', ['--help'], {
      env: {
        // by default, spawn uses `process.env` for the value of `env`
        // you can _add_ to this behavior, by spreading `process.env`
        ...process.env,
        OTHER_ENV_VARIABLE: 'test',
      }
    });
    

提交回复
热议问题