Merge pull request #5171 from tdzl2003/tdzl2003-pr-2

Fix 'Error: spawn npm ENOENT' on Windows
This commit is contained in:
Martin Konicek 2016-01-07 16:56:30 +00:00
commit 749f32b1e5
1 changed files with 9 additions and 1 deletions

View File

@ -42,6 +42,7 @@ var spawn = require('child_process').spawn;
var chalk = require('chalk');
var prompt = require('prompt');
var semver = require('semver');
var os = require('os');
var CLI_MODULE_PATH = function() {
return path.resolve(
@ -198,7 +199,14 @@ function run(root, projectName, logLevel) {
if (logLevel === 'debug' || logLevel === 'verbose') {
spawnArgs = {stdio: 'inherit'};
}
var proc = spawn('npm', args, spawnArgs);
var proc;
if (os.platform() === 'win32'){
args.unshift('npm');
args.unshift('/c');
proc = spawn('cmd', args, spawnArgs);
} else {
proc = spawn('npm', args, spawnArgs);
}
proc.on('close', function (code) {
if (code !== 0) {
console.error('`npm install --save react-native` failed');