描述: 上代码
var ps = require('child_process').spawn("npm", ['install'], { stdio: 'inherit', cwd: srcPath }); ps.on('error', function(err) { console.log(err); }); ps.on('exit', function (err) { console.log('exit'); });
原因,windows下npm执行名不同
解决方案
var ps = require('child_process').spawn(process.platform === "win32" ? "npm.cmd" : "npm", ['install'], { stdio: 'inherit', cwd: srcPath });
参考:http://*.com/questions/17516772/using-nodejss-spawn-causes-unknown-option-and-error-spawn-enoent-err