【问题标题】:Gulp-Notify Error - dest.on is not a functionGulp-Notify 错误 - dest.on 不是函数
【发布时间】:2019-04-11 17:32:34
【问题描述】:

我正在尝试使用 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!"))
        }));
});

知道它可能是什么吗?

感谢您的帮助!

谢谢!

布拉德

【问题讨论】:

    标签: node.js gulp gulp-notify


    【解决方案1】:

    测试了您的任务,错误来自您的through,而不是来自notify。

    如果您删除此管道,它会正常运行。 gulp-through documentation 显示了一个示例,但我找不到 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();
    });
    

    【讨论】:

    • 我喜欢这个主意。但是,在这种情况下,每当出现错误时,它都不会给我错误消息通知。它只是失败并在终端内显示正常错误。相反,我希望它像 gulp-notify 那样给我一个通知,但会出现错误。
    猜你喜欢
    • 2016-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 2018-07-08
    相关资源
    最近更新 更多