gulpfile错误AssertionError [ERR_ASSERTION]:必须指定任务功能

时间:2019-09-22 21:44:16

标签: gulp gulp-watch

当我在终端上运行gulp时,我一直在获取此堆栈跟踪。我已将gulp版本3.9.1降级,但仍然遇到相同的错误。我在网上阅读了降级可以解决此问题的信息,但目前似乎无济于事。

AssertionError [ERR_ASSERTION]: Task function must be specified
    at Gulp.set [as _setTask] (/Users/ABC/react_site/my-react-project/node_modules/undertaker/lib/set-task.js:10:3)
    at Gulp.task (/Users/yasirk/react_site/my-react-project/node_modules/undertaker/lib/task.js:13:8)
    at Object.<anonymous> (/Users/ABC/react_site/my-react-project/gulpfile.js:37:6)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

这是我的gulpfile.js

'use strict';

//dependenices
var gulp = require('gulp');
var sass = require('gulp-sass');
var minifyCSS = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var changed = require('gulp-changed');


//////////////
// -SCSS/CSS
//////////////

var SCSS_SRC = '.src/Assets/scss/**/*.scss';
var SCSS_DEST = './src/Assets/css';

//Compile CSS
gulp.task('compile_scss', function(){

    gulp.src(SCSS_SRC)
    .pipe(sass().on('error', sass.logError))
    .pipe(minifyCSS())
    .pipe(rename({suffix: '.min' }))
    .pipe(changed(SCSS_DEST))
    .pipe(gulp.dest(SCSS_DEST));

});

// detect changes in SCSS
gulp.task('watch_scss', function(){
    gulp.watch(SCSS_SRC, ['compile_scss']);
});

// Run tasks
gulp.task('default', ['watch_scss']);

这是我的package.json,您可以看到我的gulp版本已降级

{
  "name": "my-react-project",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-scripts": "3.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "gulp": "3.9.1",
    "gulp-changed": "^4.0.1",
    "gulp-clean-css": "^4.2.0",
    "gulp-rename": "^1.4.0",
    "gulp-sass": "^4.0.2",
    "gulp-uglify": "^3.0.2"
  }
}

1 个答案:

答案 0 :(得分:1)

希望它可以在您的代码中使用。

gulp.task('compile_scss', function () {
    return gulp.src(SCSS_SRC)
        .pipe(scss().on('error', scss.logError))
        .pipe(minifyCSS())
        .pipe(rename({suffix: '.min' }))
        .pipe(changed(SCSS_DEST))
        .pipe(gulp.dest(SCSS_DEST))
});


// detect changes in SCSS
gulp.task('watch_scss', function(){
    gulp.watch(SCSS_SRC, gulp.parallel('compile_scss'));
});

// Run tasks
gulp.task('default', gulp.parallel('watch_scss'));