gpt4 book ai didi

javascript - Gulp 断言错误 [ERR_ASSERTION] : Task function must be specified after Node and NPM update

转载 作者:行者123 更新时间:2023-11-29 18:47:47 27 4
gpt4 key购买 nike

我刚开始学习 gulp,我遵循了这个教程系列:https://www.youtube.com/watch?v=ax0ykSVPufs&list=PLriKzYyLb28lp0z-OMB5EYh0OHaKe91RV&index=7

在我更新我的节点和 npm 版本之前,我让这一切正常工作,我遇到了一个错误。这是我的 gulpfile.js

const gulp = require('gulp');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const autoprefixer = require('gulp-autoprefixer');
const sourcemaps = require('gulp-sourcemaps');
const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');

let styleSource = 'src/scss/style.scss';
let styleDestination = './build/css/';
let styleWatch = 'src/scss/**/*.scss';
let jsSource = 'main.js';
let jsFolder = 'src/js/';
let jsDestination = './build/js/';
let jsWatch = 'src/js/**/*.js';
let jsFILES = [jsSource];
let htmlWatch = '**/*.html';


/* Converting Sass to CSS */
gulp.task('styles',function(){
gulp.src(styleSource)
.pipe(sourcemaps.init())
.pipe(sass({
errorLogToConsole: true,
outputStyle: 'compressed'
}))
.on('error', console.error.bind(console))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(rename({suffix:'.min'}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(styleDestination));
});

/* Converting ES6 to Vanilla JS */
gulp.task('js',function(){
jsFILES.map(function(entry){
return browserify({
entries: [`${jsFolder}${entry}`]
})
.transform(babelify, {presets:['env']})
.bundle()
.pipe(source(entry))
.pipe( rename({extname:'.min.js'}) )
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(jsDestination))
});

})

// default task to run all tasks
gulp.task('default', ['styles','js']);

// watch default
gulp.task('watch', ['default'], function(){
gulp.watch(styleWatch, ['styles']);
gulp.watch(jsWatch, ['js']);
gulp.watch(htmlWatch);
});

在终端输入 gulp 命令后,我得到了这个错误:

assert.js:42
throw new errors.AssertionError({
^

AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (D:\Web Design and Development\Tutorials\Web Design and Development\My Javascript Skills Projects\javascript30\javascript30-day-two\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (D:\Web Design and Development\Tutorials\Web Design and Development\My Javascript Skills Projects\javascript30\javascript30-day-two\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (D:\Web Design and Development\Tutorials\Web Design and Development\My Javascript Skills Projects\javascript30\javascript30-day-two\gulpfile.js:63:6)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)

最佳答案

欢迎使用 Gulp。 gulp 4!

可能您的教程是针对 Gulp 3 的

gulp.task('default', ['styles','js']);

由于新的任务执行系统,将无法在 Gulp 4 中工作

相反,你必须做类似的事情

gulp.task('default', gulp.parallel('styles','js'))

gulp.task('watch', ['default'], function(){... 相同

更多细节:

https://www.liquidlight.co.uk/blog/how-do-i-update-to-gulp-4/

https://fettblog.eu/gulp-4-parallel-and-series/

关于javascript - Gulp 断言错误 [ERR_ASSERTION] : Task function must be specified after Node and NPM update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52645889/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com