Skip to content
This repository has been archived by the owner on Apr 22, 2023. 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

@brzpegasus
Copy link

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
Copy link

domenic commented Jul 13, 2013

This is caused by #2318.

@brzpegasus
Copy link
Author

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
Copy link

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

zenorocha pushed a commit to zenorocha/alloy-ui that referenced this issue Jun 13, 2014
eduardolundgren pushed a commit to eduardolundgren/alloy-ui that referenced this issue Jun 18, 2014
@ijlalkhanzada
Copy link

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
Copy link

bsed commented May 28, 2016

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

@ayo123
Copy link

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
Copy link

@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.
Projects
None yet
Development

No branches or pull requests

7 participants