Error: spawn npm ENOENT
Just changed this line
const child = spawn('npm', ['run', service]);
to this line
const child = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['run', service]);
Which is checking the operating system if ti's windows it runs npm.cmd if it's linux just npm
I faced the same problem. My application code was running fine in MAC but in Windows it was giving an error about the code related to the spawn command
The error occurs when running using command prompt
When I used GIT bash
to start the application then the error did not occur. I did not need to change any code
I know there is a correct answer and this question has been around for a long time, my solution is based on the answer @Armen Sanoyan and How do I determine the current operating system with Node.js
For me the @Armen Sanoyan answer does not work, but help a lot. I changed for this line and work.
const child = (process.platform === 'win32' ? 'npm.cmd' : 'npm') + ' run ' + service;
I hope I can help.