Javascript Gulp:控制台错误,assert.js:90 抛出新的 assert.AssertionError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38182410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gulp: error in console, assert.js:90 throw new assert.AssertionError
提问by Lebiediev
I get such an error in console: $ gulp
我在控制台中收到这样的错误:$ gulp
assert.js:90
throw new assert.AssertionError({
^
AssertionError: Task function must be specified
at Gulp.set [as _setTask] (C:\Users\user\Projects\New project\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (C:\Users\user\Projects\New project\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (C:\Users\user\Projects\New project\gulpfile.js:44:6)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
Here is my gulpfile:
这是我的 gulpfile:
var gulp = require('gulp');
var build = require('gulp-build');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var browser_sync = require('browser-sync');
var gulps = require("gulp-series");
//gulp-build
gulp.task('build', function() {
gulp.src('scripts/*.js')
.pipe(build({
GA_ID: '123456'
}))
.pipe(gulp.dest('dist'))
});
//gulp-sass
gulp.task('sass', function() {
return gulp.src('scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
errLogToConsole: true,
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('css'));
});
//gulp-browser-sync
gulp.task('browser_sync', function() {
var files = [
'*.html',
'css/*.css'
];
browser_sync.init(files, {
server: {
baseDir: './'
}
});
});
//gulp-watch
gulp.task('watch', ['sass'], function() {
gulp.watch('scss/**/*.scss', ['sass']);
});
//gulp-series
gulps.registerTasks({
"test1": (function(done) {
setTimeout(function() {
console.log("test1 is done");
done();
}, 1000);
}),
"test2": (function() {
console.log("test2 is done");
})
});
gulps.registerSeries("default", ["test1", "test2"]);
// gulp.task('default', ['watch', 'browser_sync'], function() {});
I'm just a beginner, have you any idea what I've done wrong?
我只是一个初学者,你知道我做错了什么吗?
回答by DAXaholic
I think you use gulp 4 with the gulp 3 'syntax'.
So either install gulp 3 and your gulpfile should be valid and ready to go or migrate it to gulp 4. Hereis a good article about that.
我认为您将 gulp 4 与 gulp 3 的“语法”一起使用。
因此,要么安装 gulp 3 并且您的 gulpfile 应该是有效的并且可以使用,要么将其迁移到 gulp 4。这是一篇关于此的好文章。
Changelogof gulp
更新日志一饮而尽的
回答by Dan Alboteanu
gulp 4 series(...tasks)
gulp 4 系列(...任务)
gulp.task('one', function(done) {
// do stuff
done();
});
gulp.task('two', function(done) {
// do stuff
done();
});
gulp.task('default', gulp.series('one', 'two', function(done) {
// do more stuff
done();
}));
回答by Basavaraj Hadimani
gulp automatically installs version 4.0.0
gulp 自动安装 4.0.0 版本
change the version of your gulp by running below command
通过运行以下命令来更改您的 gulp 版本
npm install [email protected] --save
This will solve your problem.
这将解决您的问题。
回答by Suresh Suthar
I resolved issue using below command
我使用以下命令解决了问题
npm install --save-dev [email protected]
This will solve your problem (I resolved issue in window 7 and window 10)
这将解决您的问题(我解决了窗口 7 和窗口 10 中的问题)
回答by giovannipds
Just passed for the same error now, DAXaholic's answeris right, your gulpfile.js
's gulp@3.* but you have installed gulp 4. Just install the correct version:
现在刚刚通过了同样的错误,DAXaholic 的答案是正确的,你gulpfile.js
的 gulp@3.* 但你已经安装了 gulp 4。只需安装正确的版本:
npm i -D gulp@3.*
回答by Nandu Hulsure
Change in the package.json to install old or latest version of Gulp as below:
更改 package.json 以安装旧版本或最新版本的 Gulp,如下所示:
"gulp": "^3.9.1",
check your CLI Version and Local version of Gulp with gulp -v command.
使用 gulp -v 命令检查 Gulp 的 CLI 版本和本地版本。
CLI version 3.9.1
Local version 3.9.1
CLI 版本 3.9.1
本地版本 3.9.1
if it's not equal this error may occur.
回答by Leo
Also an important thing to notice, if you get the
还有一个重要的事情要注意,如果你得到
"AssertionError: Task never defined: two"
“断言错误:任务从未定义:两个”
Probably it's because the tasks should be in sequence, so first task one task two and then the task with the
可能是因为任务应该是有顺序的,所以先任务一任务二,然后任务有
gulp.series('one', 'two')
gulp.series('一', '二')
回答by Jo?o Dessain Saraiva
I solved the problem with:
我解决了这个问题:
npm install gulp-cli -g npm install gulp -D npx -p touch nodetouch gulpfile.js
The default installation commands available at gulp.js Hope it helps,
gulp.js 提供的默认安装命令希望它有帮助,