-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Fix 'Error: spawn npm ENOENT' on Windows #5171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. npm is actually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To run things via shell, there is https://nodejs.org/dist/latest-v4.x/docs/api/child_process.html#child_process_child_process_exec_command_options_callback. Wouldn't it be safer to use that instead of hardcoding |
||
| } else { | ||
| proc = spawn('npm', args, spawnArgs); | ||
| } | ||
| proc.on('close', function (code) { | ||
| if (code !== 0) { | ||
| console.error('`npm install --save react-native` failed'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we use mostly
process.platformthroughout the codebase.