Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was 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

Description

@brzpegasus

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions