我有Windows 10专业版, 从这里https://vk.com/video-160048630_456239048?list=b31c949319120bc599
开始锻炼已安装gulp,gulp-less,gulp-notify和gulp-plumber。
我创建了gulp任务,这些任务将.less文件转换为.css。
运行gulp任务时,它会引发错误:
$ gulp default
$ gulp 'default'
assert.js:42
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (C:\Users\Anatoly\Desktop\project\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (C:\Users\Anatoly\Desktop\project\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (C:\Users\Anatoly\Desktop\project\gulpfile.js:8:6)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
我的gulpfile.js:
var gulp = require('gulp'),
browserSync = require('browser-sync'),
less = require('gulp-less'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber');
gulp.task('server',['less'],function(){
browserSync.init({
server: {baseDir: './app/'}
});
gulp.watch('app/**/*.html').on('change',browserSync.reload);
gulp.watch('app/less/**/*.less',['less']);
});
gulp.task('less',function(){
return gulp.src('./app/less/main.less')
.pipe(plumber({
errorHandler: notify.onError(function(err){
return {
title: 'less',
sound: false,
message: err.message
}
})
}))
.pipe(less())
.pipe(gulp.dest('./app/css'))
.pipe(browserSync.stream());
});
gulp.task('default',['server']);
答案 0 :(得分:1)
重新安装版本较少的gulp后,问题消失了:
npm uninstall gulp
-去除口水
npm i gulp --save-dev
-安装本地版本3.9.1
运行gulp任务:
gulp server
有效。