我试着在我的终端上运行gulp
命令,在我的项目目录中有gulpfile.js
,但是我得到了错误,The following tasks did not complete: default, gulpSass; Did you forget to signal async completion
,我试着寻找一个解决方案,但是没有结果。
我检查了一些可能的原因,为什么我要面对这个问题,并实现了一些,但我仍然不断地得到错误。
我尝试过的一个可能的修复方法是在所有函数中使用async await
,但它并没有解决这个问题。
这是我的gulpfile.js
var gulp = require('gulp'),
sass = require('gulp-sass'),
plumber = require('gulp-plumber'),
notify = require('gulp-notify'),
livereload = require('gulp-livereload')
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
// Concat all js into one script
async function js ( cb ) {
return await gulp.src(['./assets/js/lib/*.js','./assets/js/scripts/**/*.js'])
.pipe(plumber(plumberErrorHandler))
//.pipe(jshint())
//.pipe(jshint.reporter('jshint-stylish'))
.pipe(sourcemaps.init())
.pipe(concat('scripts.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write('../maps/'))
.pipe(gulp.dest('./assets/js'))
.pipe(livereload());
cb();
}
// Sass compiler + Maps
async function sass ( cb ) {
return await gulp.src('./assets/scss/*.scss')
.pipe(plumber(plumberErrorHandler))
.pipe(sassGlob())
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'development'}))
//.pipe(autoprefixer({
// browsers: ['>1%'],
//remove: false
//}))
.pipe(sourcemaps.write('./assets/maps'))
.pipe(gulp.dest('.'))
.pipe(livereload());
cb();
}
// Watch for changes
async function watch ( cb ) {
livereload.listen();
return await gulp.watch('./assets/scss/**/*', ['sass']);
return await gulp.watch('./assets/js/lib/**/*.js', ['js']);
return await gulp.watch('./assets/js/scripts/**/*.js', ['js']);
return await gulp.watch('./**/*.php').on('change', async function(file) {
livereload.changed(file.path);
});
cb();
}
// Error handling/reporting
var plumberErrorHandler = {
errorHandler: notify.onError({
title: 'Gulp',
message: 'Error: <%= error.message %>'
})
}
// Default
exports.default = gulp.series(js, sass, watch);
发布于 2022-01-05 20:43:20
首先,您的错误消息是The following tasks did not complete: default, gulpSass;
,但是代码中没有gulpSass
任务,所以在这里复制它之前,您更改了一些内容。
第二,这个语法是旧的:
return await gulp.watch('./assets/scss/**/*', ['sass']);
用这个代替:
gulp.watch('./assets/scss/**/*', sass);
您使用的是任务的函数名称形式,而不是gulp.task('sass')
语法,因此在监视调用中使用函数名sass
,而不是作为字符串'sass'
。
在整个watch
任务中进行此更改。
我会摆脱return await
--这可能是个问题。
https://stackoverflow.com/questions/70551037
复制相似问题