events.js:72
throw er; // Unhandled \'error\' event
^
Error: spawn ENOENT
at errnoException (chil
@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:
const s = cp.spawn('npm install -D suman', [], {
cwd: root
});
this is incorrect:
const s = cp.spawn('npm', ['install -D suman'], {
cwd: root
});
this is correct:
const s = cp.spawn('npm', ['install','-D','suman'], {
cwd: root
});
however, I recommend doing it this way:
const s = cp.spawn('bash');
s.stdin.end(`cd "${root}" && npm install -D suman`);
s.once('exit', code => {
// exit
});
this is because then the cp.on('exit', fn)
event will always fire, as long as bash is installed, otherwise, the cp.on('error', fn)
event might fire first, if we use it the first way, if we launch 'npm' directly.