Windows 7
Node v0.12.3
Npm v2.9.1
I'm using gulp to handle dev tasks. I'm trying to add gulp-nodemon so that I can auto-restart nodejs when files change. I want to run the task process to build/transform source files prior to restarting node, like so:
var nodemon = require('gulp-nodemon');
gulp.task('develop', function () {
nodemon({
script: 'server.js',
tasks: ['process']
});
});
gulp-nodemon uses child_process.spawnSync('gulp', tasks, ...) to execute these tasks.
While investigating why this didn't work, I found the object returned by spawnSync() always has an error property, containing an ENOENT error.
I can reproduce this easily using gulp:
var gulp = require('gulp');
var cp = require('child_process');
gulp.task('test', function () {
// outputs directory listing to stdout
var lsProcess = cp.spawnSync('ls', [], {stdio: [0, 1, 2]});
console.log(lsProcess.error); // undefined
// no output
var gulpProcess = cp.spawnSync('gulp', ['sayhi'], {stdio: [0, 1, 2]});
console.log(gulpProcess.error); // ENOENT
});
gulp.task('sayhi', function () {
// never runs
console.log('Hi!');
});
Running gulp test gives this output:
[19:47:13] Starting 'test'...
app.js auth.js components config db gulpfile.js middleware node_modules nodemon.json package.json public router server.js views
undefined
{ [Error: spawnSync ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawnSync' }
[19:47:13] Finished 'test' after 12 ms
proving that gulp is available in the command prompt but not in the child process.
As you can see, the ls command gives a directory listing and undefined for .error, while gulp sayhi gives no output and an ENOENT for .error.
Other non-system commands (I'm on Windows 7 with some aliases for *nix commands) and executables available in the PATH appear to work fine: ls, cat, notepad, node.. but cd, dir, path and - importantly - gulp (which is an npm module) all fail.
Is there something different about the environment the child process is using? How are npm modules made available to the commandline in Windows and could this affect what is available to spawnSync()?
spawnSync('gulp', ['test'], {env: process.env, stdio: [0, 1, 2]});, copying the current environment, doesn't change a thing.
spawnSync('bash', ['gulp', 'sayhi'], {stdio: [0, 1, 2]}); works fine by deferring the command to bash.
Windows 7
Node v0.12.3
Npm v2.9.1
I'm using gulp to handle dev tasks. I'm trying to add gulp-nodemon so that I can auto-restart nodejs when files change. I want to run the task
processto build/transform source files prior to restarting node, like so:gulp-nodemon uses
child_process.spawnSync('gulp', tasks, ...)to execute these tasks.While investigating why this didn't work, I found the object returned by
spawnSync()always has anerrorproperty, containing anENOENTerror.I can reproduce this easily using gulp:
Running
gulp testgives this output:proving that
gulpis available in the command prompt but not in the child process.As you can see, the
lscommand gives a directory listing andundefinedfor.error, whilegulp sayhigives no output and anENOENTfor.error.Other non-system commands (I'm on Windows 7 with some aliases for *nix commands) and executables available in the
PATHappear to work fine:ls,cat,notepad,node.. butcd,dir,pathand - importantly -gulp(which is an npm module) all fail.Is there something different about the environment the child process is using? How are npm modules made available to the commandline in Windows and could this affect what is available to
spawnSync()?spawnSync('gulp', ['test'], {env: process.env, stdio: [0, 1, 2]});, copying the current environment, doesn't change a thing.spawnSync('bash', ['gulp', 'sayhi'], {stdio: [0, 1, 2]});works fine by deferring the command to bash.