我有一个JS应用程序。它在linux上运行良好,但在windows 10中,我得到了一个错误。
events.js:161
throw er; // Unhandled 'error' event
^
Error: spawn npm ENOENT
at exports._errnoException (util.js:1028:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
at Module.runMain (module.js:607:11)
at run (bootstrap_node.js:422:7)
at startup (bootstrap_node.js:143:9)
at bootstrap_node.js:537:3不正确的代码是
const spawn = require('child_process').spawn;
const watching = [
// {service: "babel-watch"},
{service: "webpack-watch"},
// {service: "sass-watch"},
{service: "server-watch"}
];
watching.forEach(({service}) => {
const child = spawn('npm', ['run', service]);
child.stdout.on('data', d => console.log(d.toString()));
child.stderr.on('data', d => console.log(d.toString()));
});我在github中发现了这个错误的原因,我想问题是产生了nodejs产卵医生,它在windows中没有正常工作。但我不知道如何修改这段代码以使其工作。有人能帮我吗?
发布于 2017-04-07 18:44:45
刚换了这条线
const child = spawn('npm', ['run', service]);到这条线
const child = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['run', service]);它检查操作系统,如果ti的窗口,它运行npm.cmd,如果它是linux,只是npm
发布于 2021-02-01 15:07:12
我知道答案是正确的,这个问题已经存在很长时间了,我的解决方案是基于@Armen Sanoyan和如何使用Node.js确定当前操作系统的答案。
对我来说,@Armen Sanoyan的答案不起作用,但有很大帮助。我换了这条线和工作。
const child = (process.platform === 'win32' ? 'npm.cmd' : 'npm') + ' run ' + service;希望我能帮上忙。
发布于 2019-10-07 08:44:13
我也面临着同样的问题。我的应用程序代码在MAC中运行得很好,但是在Windows中,它给出了一个与生成命令相关的代码错误
使用command prompt运行时会发生错误
当我使用GIT bash启动应用程序时,没有出现错误。我不需要修改任何代码
https://stackoverflow.com/questions/43230346
复制相似问题