1

我正在尝试使用 Gulp-Notify 的错误处理功能,但我不断收到以下错误:

TypeError: dest.on is not a function

我按照此处的说明进行操作: https ://www.npmjs.com/package/gulp-notify#notifyonerror但不断收到相同的错误。

这是我的文件:

const gulp     = require('gulp');
const rename   = require('gulp-rename');
const sass     = require('gulp-sass');
const cleancss = require('gulp-clean-css');
var plumber    = require("gulp-plumber");
var through    = require('gulp-through');
var notify     = require("gulp-notify");

gulp.task('styles', function(){
    gulp.src('builders/stylesheets/style.scss')
        .pipe(sass())
        .pipe(cleancss())
        .pipe(rename('style.min.css'))
        .pipe(gulp.dest('assets/css'))
        .pipe(notify("Saved Styles!"))
        .pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
        .pipe(through(function () {
          this.emit("error", new Error("Something happend: Error message!"))
        }));
});

知道它可能是什么吗?

我很感激任何帮助!

谢谢!

布拉德

4

1 回答 1

1

Tested your task and the error comes from your through and not from the notify.

If you delete this pipe it runs without problems. The gulp-through documentation shows an example, but i couldn't find there a usecase with pipe.

gulp.task('styles', function(cb){
    gulp.src('builders/stylesheets/style.scss')
        .pipe(sass())
        .pipe(cleancss())
        .pipe(rename('style.min.css'))
        .pipe(gulp.dest('assets/css'))
        .pipe(notify("Saved Styles!"))
        .pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))

    cb();
});
于 2019-04-11T18:09:35.650 回答