操作系统:Windows 10 Pro
节点:6.5.0
NPM:3.10.3
Gulp:CLI版本3.9.1
所以我在gulp(构建)过程中,在触发进程的runSequence
时,仅在Windows上收到以下错误。关于如何解决它的任何想法?:
[14:44:57] Finished 'eslint-ci' after 18 s
[14:44:57] Starting 'ava'...
events.js:160
throw er; // Unhandled 'error' event
^
Error: spawn npm ENOENT
at exports._errnoException (util.js:1026:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)

代码如下:
import runSequence from 'run-sequence';
gulp.task('to-html', done => {
args.production = true;
process.env.IS_SERVERLESS = true;
const fetch = url => new Promise((resolve, reject) => {
http.get({ host: 'localhost', path: url, port: 3000 }, res => {
// Explicitly treat incoming data as utf8 (avoids issues with multi-byte).
res.setEncoding('utf8');
let body = '';
res.on('data', data => {
body += data;
});
res.on('end', () => resolve(body));
}).on('error', reject);
});
const moveAssets = () => {
const assets = fs.readdirSync('build');
fs.mkdirSync(path.join('build', 'assets'));
assets.forEach(fileName => {
fs.renameSync(
path.join('build', fileName),
path.join('build', 'assets', fileName)
);
});
};
const toHtml = () => {
const promises = Object.keys(urls).map(url => fetch(url).then(html => {
fs.writeFile(path.join('build', urls[url]), html);
}));
return Promise.all(promises);
};
runSequence('eslint-ci', 'ava', 'flow', 'clean', 'build', () => {
const proc = spawn('node', ['./src/server']);
proc.stderr.on('data', data => console.log(data.toString()));
proc.stdout.on('data', async data => {
data = data.toString();
if (data.indexOf('Server started') === -1) return;
try {
moveAssets();
await toHtml();
} catch (error) {
console.log(error);
} finally {
proc.kill();
done();
console.log('App has been rendered to /build directory.');
console.log('OSX tip: cd build && python -m SimpleHTTPServer 3000');
}
});
});
});

ava.js
import childProcess from 'child_process';
import gulp from 'gulp';
gulp.task('ava', done => {
childProcess
.spawn('npm', ['run', 'ava'], { stdio: 'inherit' })
.on('close', done);
});

的package.json
"ava": {
"babel": "inherit",
"files": [
"src/**/__test__/**/*.js"
],
"source": [
"src/**/*"
],
"require": [
"babel-register",
"babel-polyfill"
]
},