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

后端 未结 25 2747
轻奢々
轻奢々 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

    I ran into the same problem, but I found a simple way to fix it. It appears to be spawn() errors if the program has been added to the PATH by the user (e.g. normal system commands work).

    To fix this, you can use the which module (npm install --save which):

    // Require which and child_process
    const which = require('which');
    const spawn = require('child_process').spawn;
    // Find npm in PATH
    const npm = which.sync('npm');
    // Execute
    const noErrorSpawn = spawn(npm, ['install']);
    

提交回复
热议问题