使用gulp 4时出现一些奇怪的错误,我只是不明白问题是什么,在我看来,这绝对没有意义。我正在使用Gulp 4和Babel,所以它是gulpfile.babel.js。
有问题的部分摘录:
const root = 'src/';
const paths = {
dist: './dist/',
scripts: [
`${root}/app/**/*.js`,
`!${root}/app/**/*.js`
],
tests: `${root}/app/**/*.spec.js`,
styles: {
src: `${root}/sass/**/*.scss`,
dest: './dist/css/'
},
templates: `${root}/app/**/*.html`
};
function watchScripts() {
gulp.watch([
paths.templates,
...paths.scripts
], scripts);
}
const watchFiles = gulp.series(scripts, gulp.parallel(watchStyles, watchScripts));
function scripts() {
return gulp.src([
`!${root}/app/**/*.spec.js`,
`${root}/app/**/*.module.js`,
'./templates.js',
...paths.scripts
])
.pipe(sourcemaps.init())
.pipe(wrap('(function(angular){\n\'use strict\';\n<%= contents %>})(window.angular);'))
.pipe(concat('bundle.js'))
.pipe(ngAnnotate())
.pipe(gulpif(argv.deploy, uglify()))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.dist + 'js/'));
}
export {
clean,
copy,
scripts,
templates,
watchFiles
}
现在问题出在任务“ watchFiles”(尤其是watchScripts-Part)之内。我可以毫无问题地运行任务“脚本”。我可以毫无问题地运行watchFiles-task并更改触发任务“脚本”的html中的内容。但是:如果我通过编辑JavaScript文件(paths.scripts)触发更改,则会引发以下错误:
> watchScripts: Starting 'scripts'...
> watchScripts: 'scripts' errored after 448 μs
> watchScripts: TypeError: Invalid attempt to spread non-iterable instance.
> watchScripts: In order to be iterable, non-array objects must have a [Symbol.iterator]() method.
> watchScripts: at _nonIterableSpread (c:\Users\Kleiber\projects\trakyourtv\gulpfile.babel.js:50:39)
> watchScripts: at _toConsumableArray (c:\Users\Kleiber\projects\trakyourtv\gulpfile.babel.js:48:131)
> watchScripts: at scripts (c:\Users\Kleiber\projects\trakyourtv\/gulpfile.babel.js:104:10)
> watchScripts: at bound (domain.js:419:14)
> watchScripts: at runBound (domain.js:432:12)
> watchScripts: at asyncRunner (c:\Users\Kleiber\projects\trakyourtv\node_modules\async-done\index.js:55:18)
> watchScripts: at processTicksAndRejections (internal/process/task_queues.js:75:11)
这对我来说绝对没有意义。脚本任务可以完全独立运行,也可以由上述HTML更改触发。为什么更改JS文件会导致此错误?