This repository has been archived by the owner. It is now read-only.

`Error: spawn ENOENT` when executing a program installed globally via npm (Windows) #5841

Closed
brzpegasus opened this Issue Jul 12, 2013 · 7 comments

Comments

Projects
None yet
7 participants
@brzpegasus

brzpegasus commented Jul 12, 2013

When I install an npm module globally, I'm able to execute it in a child process with the exec method, but not with spawn.

So, this will print the version of Express (although sometimes it won't print anything because of this other issue)...

var exec = require('child_process').exec;
exec('express --version', function(err, stdout, stderr) {
  console.log(stdout);
});

But if I use spawn instead:

var spawn = require('child_process').spawn;
spawn('express', ['--version']);

then I get this error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:980:11)
    at Process.ChildProcess._handle.onexit (child_process.js:771:34)

I believe this is only happening on Windows. I've seen this issue reported in other repos, like mocha-phantomjs, but it seems like a Node issue to me. Essentially, spawn is unable to find the command, but exec can. Shouldn't they work consistently?

I'm on Windows 7, using node v0.10.13.

@domenic

This comment has been minimized.

Show comment
Hide comment
@domenic

domenic Jul 13, 2013

Member

This is caused by #2318.

Member

domenic commented Jul 13, 2013

This is caused by #2318.

@brzpegasus

This comment has been minimized.

Show comment
Hide comment
@brzpegasus

brzpegasus Jul 13, 2013

Ahh, thanks for pointing out the true root cause. Makes more sense now why installing phantomjs.exe and adding that to the path works when you call spawn, but not when it's installed via npm. I didn't realize spawn did not handle .bat or .cmd files.

brzpegasus commented Jul 13, 2013

Ahh, thanks for pointing out the true root cause. Makes more sense now why installing phantomjs.exe and adding that to the path works when you call spawn, but not when it's installed via npm. I didn't realize spawn did not handle .bat or .cmd files.

@tjfontaine

This comment has been minimized.

Show comment
Hide comment
@tjfontaine

tjfontaine Jul 27, 2013

Maybe we should have a doc update around it, but the brunt of this issue is tracked by another, closing as a duplicate

tjfontaine commented Jul 27, 2013

Maybe we should have a doc update around it, but the brunt of this issue is tracked by another, closing as a duplicate

@tjfontaine tjfontaine closed this Jul 27, 2013

zenorocha added a commit to zenorocha/alloy-ui that referenced this issue Jun 13, 2014

eduardolundgren added a commit to eduardolundgren/alloy-ui that referenced this issue Jun 18, 2014

@ijlalkhanzada

This comment has been minimized.

Show comment
Hide comment
@ijlalkhanzada

ijlalkhanzada Oct 12, 2015

when i run cordova-splash command this error to come.
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)

ijlalkhanzada commented Oct 12, 2015

when i run cordova-splash command this error to come.
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)

@bsed

This comment has been minimized.

Show comment
Hide comment
@bsed

bsed May 28, 2016

Failed to launch external program npm run compile.
spawn npm ENOENT

bsed commented May 28, 2016

Failed to launch external program npm run compile.
spawn npm ENOENT

@ayo123

This comment has been minimized.

Show comment
Hide comment
@ayo123

ayo123 Jul 5, 2016

Adding C:\Windows\System32\ to my system PATH in Environment variable and restarting my cmd fixed the problem for me.

ayo123 commented Jul 5, 2016

Adding C:\Windows\System32\ to my system PATH in Environment variable and restarting my cmd fixed the problem for me.

@flyskywhy

This comment has been minimized.

Show comment
Hide comment
@flyskywhy

flyskywhy Sep 24, 2016

@brzpegasus @domenic @tjfontaine @ijlalkhanzada @d0f @ayo123 , this issue was resolved in #2318 :

e.g. npm, just replace

spawn('npm', ...

by

spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ...

flyskywhy commented Sep 24, 2016

@brzpegasus @domenic @tjfontaine @ijlalkhanzada @d0f @ayo123 , this issue was resolved in #2318 :

e.g. npm, just replace

spawn('npm', ...

by

spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.