Javascript 每次在命令行中运行gulp时,我都会遇到断言错误

Javascript 每次在命令行中运行gulp时,我都会遇到断言错误,javascript,gulp,Javascript,Gulp,我正在尝试运行下面的命令,但不幸的是,我遇到了一个错误 C:\Users\usver\Desktop\git test\git\Bootstrap4\conFusion>gulp 运行上述命令后,我得到了断言错误。我重新安装了gulp和npm,但得到了相同的错误。 我的节点版本-v10.15.0 吞咽版- CLI版本2.0.1 本地版本4.0.2 assert.js:350 throw err; ^ AssertionError [ERR_ASSERTION]: Tas

我正在尝试运行下面的命令,但不幸的是,我遇到了一个错误

C:\Users\usver\Desktop\git test\git\Bootstrap4\conFusion>gulp
运行上述命令后,我得到了断言错误。我重新安装了gulp和npm,但得到了相同的错误。 我的节点版本-v10.15.0 吞咽版- CLI版本2.0.1 本地版本4.0.2

assert.js:350
    throw err;
    ^

AssertionError [ERR_ASSERTION]: Task function must be specified
    at Gulp.set [as _setTask] (C:\Users\usver\Desktop\git test\git\Bootstrap4\conFusion\node_modules\undertaker\lib\set-task.js:10:3)
    at Gulp.task (C:\Users\usver\Desktop\git test\git\Bootstrap4\conFusion\node_modules\undertaker\lib\task.js:13:8)
    at Object.<anonymous> (C:\Users\usver\Desktop\git test\git\Bootstrap4\conFusion\gulpfile.js:30:6)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
package.json文件

{
  "name": "confusion",
  "version": "1.0.0",
  "description": "This is a website for Ristorante Con Fusion",
  "main": "index.html",
  "scripts": {
    "start": "npm run watch:all",
    "test": "echo \"Error: no test specified\" && exit 1",
    "lite": "lite-server",
    "scss": "node-sass -o css/ css/",
    "watch:scss": "onchange \"css/*.scss\" --npm run scss",
    "watch:all": "parallelshell \"npm run watch:scss\" 'npm run lite'",
    "clean": "rimraf dist",
    "copyfonts": "copyfiles -f node_modules/font-awesome/fonts/* dist/fonts",
    "imagemin": "imagemin img/* -o dist/img",
    "usemin": "usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html",
    "build": "npm run clean && npm run copyfonts && npm run imagemin && npm run usemin"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "browser-sync": "^2.26.7",
    "cssmin": "^0.4.3",
    "del": "^3.0.0",
    "grunt-browser-sync": "^2.2.0",
    "grunt-cli": "^1.2.0",
    "grunt-contrib-clean": "^1.1.0",
    "grunt-contrib-concat": "^1.0.1",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-contrib-cssmin": "^2.2.1",
    "grunt-contrib-htmlmin": "^2.4.0",
    "grunt-contrib-imagemin": "^3.1.0",
    "grunt-contrib-uglify": "^3.3.0",
    "grunt-contrib-watch": "^1.1.0",
    "grunt-filerev": "^2.3.1",
    "grunt-sass": "^2.1.0",
    "grunt-usemin": "^3.1.1",
    "gulp": "^4.0.2",
    "gulp-sass": "^3.1.0",
    "htmlmin": "0.0.7",
    "jit-grunt": "^0.10.0",
    "lite-server": "^2.3.0",
    "node-sass": "^4.12.0",
    "onchange": "^6.0.0",
    "parallelshell": "^3.0.2",
    "rimraf": "^2.6.2",
    "time-grunt": "^1.4.0",
    "uglifyjs": "^2.4.11",
    "usemin-cli": "^0.5.1"
  },
  "dependencies": {
    "bootstrap": "^4.3.1",
    "bootstrap-social": "^5.1.1",
    "font-awesome": "^4.7.0",
    "grunt": "^1.0.4",
    "jquery": "^3.4.1",
    "popper.js": "^1.12.9"
  }
}

我已经包含了gulp.js和package.json文件。

您正在gulp4文件中使用gulp3语法

搜索您的错误消息必须指定任务功能
,您将获得大量点击

更改这些行:

gulp.task('sass:watch',function(){
    // gulp.watch('./css/*.scss',['sass']);

    gulp.watch('./css/*.scss', gulp.series('sass'));
    // gulp.watch('./css/*.scss', 'sass');    // should work too
});


看起来您是在学习一本旧的gulp3教程,但请寻找一些从gulp3到gulp4的迁移指南。

太好了,如果您觉得答案有用且准确,请不要忘记接受它(单击复选标记)。谢谢
gulp.task('sass:watch',function(){
    // gulp.watch('./css/*.scss',['sass']);

    gulp.watch('./css/*.scss', gulp.series('sass'));
    // gulp.watch('./css/*.scss', 'sass');    // should work too
});
// gulp.task('default',['browser-sync'],function(){
    //gulp.start('sass:watch');
// });
gulp.task('default', gulp.series('browser-sync', 'sass:watch'));