Skip to content
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

child_process.spawn does not work with npm run scripts on windows. #2

Merged
merged 13 commits into from
Nov 6, 2015

Conversation

sanemat
Copy link
Owner

@sanemat sanemat commented Nov 5, 2015

child_process.spawn does not work with npm run scripts on windows.

# package.json
{
  "dependencies": {
    "touch": "^1.0.0"
  },
  "scripts": {
    "test": "npm run touch1 --verbose && node test.js",
    "touch1": "touch foo.txt"
  }
}

# test.js
var spawn = require('child_process').spawn;
var touch1 = spawn('npm', ['run', 'touch1', '--verbose'], { stdio: 'inherit' });
touch1.on('error', function(err) {
  console.error(err);
  process.exit(1);
});

npm run touch1 works fine both linux and windows.

spawn('npm', ['run', 'touch1']) works fine on linux.
https://travis-ci.org/sanemat/node-windows-spawn-confirm/builds/89416274
But this does not work on windows.
https://ci.appveyor.com/project/sanemat/node-windows-spawn-confirm/build/1.0.2

{ [Error: spawn npm ENOENT]
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn npm',
  path: 'npm' }

Is this nodejs issue? or npm issue?

@sanemat sanemat changed the title chore(npm): run npm scripts child_process.spawn does not work with npm run scripts on windows. Nov 5, 2015
@sanemat
Copy link
Owner Author

sanemat commented Nov 6, 2015

if (windowsEnvironment) {
  var cmd = 'npm.cmd'
} else {
  var cmd = 'npm'
}
spawn(cmd, ['run', 'touch1'])

sanemat added a commit that referenced this pull request Nov 6, 2015
child_process.spawn does not work with npm run scripts on windows.
@sanemat sanemat merged commit f827764 into master Nov 6, 2015
@sanemat sanemat deleted the chore/npm-scripts branch November 6, 2015 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant