1

I am trying to use Gulp-Notify's error handling function, but I keep getting the following error:

TypeError: dest.on is not a function

I am following the instructions here: https://www.npmjs.com/package/gulp-notify#notifyonerror but keep getting the same error.

Here is my file:

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!"))
        }));
});

Any idea what it could be?

I appreciate any of the help!

Thanks!

Brad

Brad Ahrens
  • 4,864
  • 5
  • 36
  • 47

1 Answers1

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();
});
d-h-e
  • 2,478
  • 1
  • 10
  • 18
  • I like the idea. However, in this case, whenever there is an error, it does not give me the error message notification. It merely fails and shows the normal error within terminal. Instead, I would like it to give me a notification like gulp-notify does, but with the error. – Brad Ahrens Apr 11 '19 at 22:24