When I get the following error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:1000:11)
at Process.ChildProcess._handle.onexit (child_process.js:791:34)
What procedure can I follow to fix it?
Author note: Lots of issues with this error encouraged me to post this question for future references.
Related questions:
- using spawn function with NODE_ENV=production
- node.js child_process.spawn ENOENT error - only under supervisord
- spawn ENOENT node.js error
- https://stackoverflow.com/questions/27603713/nodejs-spawn-enoent-error-on-travis-calling-global-npm-package
- Node JS - child_process spawn('npm install') in Grunt task results in ENOENT error
- Running "foreman" task Fatal error: spawn ENOENT
- unhandled error event in node js Error: spawn ENOENT at errnoException (child_process.js:975:11)
- Node.js SpookyJS: error executing hello.js
- https://stackoverflow.com/questions/26572214/run-grunt-on-a-directory-nodewebkit
- Run exe file with Child Process NodeJS
- Node: child_process.spawn not working on Java even though it's in the path (ENOENT)
- spawn ENOENT error with NodeJS (PYTHON related)
- image resizing is not working in node.js (partial.js) (non-installed dependency)
- npm install error ENOENT (build dependency problem)
- Cannot install node.js - oracle module on Windows 7 (build dependency problem)
- Error installing gulp using nodejs on windows (strange case)
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:
for node.js 5.x and later:
Use
require('child_process').exec
instead of spawn for a more specific error message!for example:
@laconbass's answer helped me and is probably most correct.
I came here because I was using spawn incorrectly. As a simple example:
this is incorrect:
this is incorrect:
this is correct:
however, I recommend doing it this way:
this is because then the
cp.on('exit', fn)
event will always fire, as long as bash is installed, otherwise, thecp.on('error', fn)
event might fire first, if we use it the first way, if we launch 'npm' directly.As @DanielImfeld pointed it, ENOENT will be thrown if you specify "cwd" in the options, but the given directory does not exist.
I got the same error for windows 8.The issue is because of an environment variable of your system path is missing . Add "C:\Windows\System32\" value to your system PATH variable.
I was also going through this annoying problem while running my test cases, so I tried many ways to get across it. But the way works for me is to run your test runner from the directory which contains your main file which includes your nodejs spawn function something like this:
For example, this file name is test.js, so just move to the folder which contains it. In my case, it is test folder like this:
then from run your test runner in my case its mocha so it will be like this:
I have wasted my more than one day to figure it out. Enjoy!!