我有这样的功能
function startMain(){
child_process.spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['install'], {
cwd : somedir,
stdio : 'inherit'
}).on('close',()=>{
child_process.spawn('node', ['app'], {
cwd : somedir,
stdio : 'inherit'
}).on('error', (err)=>{
console.log('Error occured during starting. Aborting...\nError stack: Cannot exec node\n');
throw(err); // something wrong with spawn
});
}).on('error', (err)=>{
console.log('Error occured during starting. Aborting...\nError stack: Cannot exec npm\n');
throw(err); // something wrong with spawn
});
}
在 Windows、Linux 和 Android 机器上,我遇到相同的错误:尝试执行 npm 时出现 ENOENT。它存在于 process.env.PATH 中。我做错了什么?
PSsomedir
已定义且等于现有目录