-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
child_process.spawn
does not work with npm run scripts
on windows.
#3675
Comments
I'd say a local issue. The ENOENT error code is the operating system telling you it can't find |
@bnoordhuis On windows environment (appveyor), process.env.PATH includes npm path.
https://ci.appveyor.com/project/sanemat/node-windows-spawn-confirm/build/1.0.17/job/3u42bafouw95to63 |
Windows being Windows, I'm going to guess that you need to execute npm.cmd |
You guess this?
Ummm... |
Yes, like that. I'll close the bug report as it's not an issue with node.js itself. |
thanks. |
I can verify: |
Well, npm.cmd works to launch the process, but later when you want to kill it (e.g. touch1.kill(), assuming that you had started a process that runs forever such as a server), the kill() command silently fails to actually terminate the process. In my case, "npm start" would run "node server.js"; if I specify spawn('node', ['server.js']) it works beautifully. If I specify proc = spawn('npm.cmd', ['start']), the process is left running after I call proc.kill(). |
Above problem occurs on linux as well, its because |
Note that various npmjs.com packages exist to portably spawn npm, check them out. |
Thanks! |
In case anyone else with a similar issue finds this thread, here was my solution: const os = require('os');
const process = spawn(...); // long running process
// ... later...
if (os.platform() === 'win32') { // process.platform was undefined for me, but this works
execSync(`taskkill /F /T /PID ${process.pid}`); // windows specific
} else {
process.kill();
} |
While I can understand why the existence of a workaround could be considered a solution to this issue, I find the inclination to allow differences to proliferate between OSes disturbing. **Stands on soapbox.** JS is a cross-platform language. Node should be as well. To say that I should worry about Windows while developing in Linux on a MacBook is WRONG. And to say the bugs that come from that are my fault is WRONG. **Gets off soapbox.** |
Then use |
hi i have a problem with spawn var spawn = require('child_process').spawn;
var bower = spawn('bower', ['install',comp], { stdio: 'inherit' , shell: true});
console.log('********',comp)
bower.on('error', function(err) {
console.error(err);
process.exit(1);
});
bower.on('close', function(code) {
if (code !== 0) {
console.log('Bower failed.');
}
console.log('-------------');
});
bower.on('exit', function(code) {
if (code !== 0) {
console.log('Bower failed.');
}
console.log('-------e------');
});
} command is executed but i cant intercept when execution is finished |
./scripts/watch-demo demos/nn-art/nn-art.ts Error: spawn node_modules/.bin/watchify ENOENT How can I fix this? |
Hey everyone, not sure how relevant my comment is going to be, but i managed to run my My current example uses a Nrwl workspace, but it can work for any npm commands really.
Produces the following output in the terminal:
I'm on Node version 12 and I ran this on a Windows 10 machine without any problems. I didn't need to use |
THANK YOU SO MUCH FOR YOUR ANSWER! |
This is usually not desirable when using |
@benjamingr thanks for the response. I don't really know if I had exactly same problem, I just know that when I added the following option to my code, it started to work on windows. I'm using sfdx cli, which is built using Ocliff. The sfdx cli allow us to extend the native functionality by creating plugins. I created on plugin that was calling a standard sfdx command using spawn, and it was working fine on linux, but when I ran it on Windows it was not working at all. Then I added the option below and the problem was solved to both environments. shell: os.platform() === 'win32' |
In my case (windows, trying to run npm/yarn with spawn), passing https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options |
nice,brother! |
see: nodejs/node#3675 and in particular: nodejs/node#3675 (comment)
see: nodejs/node#3675 and in particular: nodejs/node#3675 (comment)
child_process.spawn
does not work withnpm run scripts
on windows.npm run touch1
works fine both linux and windows.spawn('npm', ['run', 'touch1'])
works fine on linux.https://travis-ci.org/sanemat/node-windows-spawn-confirm/builds/89416274
But this does not work on windows.
https://ci.appveyor.com/project/sanemat/node-windows-spawn-confirm/build/1.0.2
Is this nodejs issue? or npm issue?
confirming code: child_process.spawn does not work with npm run scripts on windows. by sanemat · Pull Request #2 · sanemat/node-windows-spawn-confirm
The text was updated successfully, but these errors were encountered: