Skip to content

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

@sanemat

Description

@sanemat

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?

confirming code: child_process.spawn does not work with npm run scripts on windows. by sanemat · Pull Request #2 · sanemat/node-windows-spawn-confirm

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.invalidIssues and PRs that are invalid.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions