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

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

    For ENOENT on Windows, https://github.com/nodejs/node-v0.x-archive/issues/2318#issuecomment-249355505 fix it.

    e.g. replace spawn('npm', ['-v'], {stdio: 'inherit'}) with:

    • for all node.js version:

      spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['-v'], {stdio: 'inherit'})
      
    • for node.js 5.x and later:

      spawn('npm', ['-v'], {stdio: 'inherit', shell: true})
      
    0 讨论(0)
  • 2020-11-22 03:23

    Before anyone spends to much time debugging this problem, most of the time it can be resolved by deleting node_modules and reinstalling the packages.

    To Install:

    If a lockfile exists you might use

    yarn install --frozen-lockfile
    

    or

    npm ci
    

    respectivly. if not then

    yarn install
    

    or

    npm i
    
    0 讨论(0)
  • 2020-11-22 03:23

    In case you're experiencing this issue with an application whose source you cannot modify consider invoking it with the environment variable NODE_DEBUG set to child_process, e.g. NODE_DEBUG=child_process yarn test. This will provide you with information which command lines have been invoked in which directory and usually the last detail is the reason for the failure.

    0 讨论(0)
  • 2020-11-22 03:23

    In my case removing node, delete all AppData/Roaming/npm and AppData/Roaming/npm-cache and installing node once again solve the issue.

    0 讨论(0)
  • 2020-11-22 03:24

    If you're on Windows Node.js does some funny business when handling quotes that may result in you issuing a command that you know works from the console, but does not when run in Node. For example the following should work:

    spawn('ping', ['"8.8.8.8"'], {});
    

    but fails. There's a fantastically undocumented option windowsVerbatimArguments for handling quotes/similar that seems to do the trick, just be sure to add the following to your opts object:

    const opts = {
        windowsVerbatimArguments: true
    };
    

    and your command should be back in business.

     spawn('ping', ['"8.8.8.8"'], { windowsVerbatimArguments: true });
    
    0 讨论(0)
  • 2020-11-22 03:25

    In my case, I was getting this error thrown due to the necessary dependent system resources not being installed.

    More specifically, I have a NodeJS app that is utilizing ImageMagick. Despite having the npm package installed, the core Linux ImageMagick was not installed. I did an apt-get to install ImageMagick and after that all worked great!

    0 讨论(0)
提交回复
热议问题