events.js:72
throw er; // Unhandled \'error\' event
^
Error: spawn ENOENT
at errnoException (chil
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})
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.
If a lockfile exists you might use
yarn install --frozen-lockfile
or
npm ci
respectivly. if not then
yarn install
or
npm i
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.
In my case removing node, delete all AppData/Roaming/npm and AppData/Roaming/npm-cache and installing node once again solve the issue.
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 });
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!