V
V
Valery2015-04-26 10:40:03
gulp.js
Valery, 2015-04-26 10:40:03

How to handle errors in Gulp?

Hello,
Can you please tell me how to make gulp-watch not fall off in case of an error (for example, when compiling LESS), but continue to work?
For error handling I use gulp-plumber:

gulp.task('less', function() {
    return gulp.src(sourceDir + '/less/style.less')
        .pipe(plumber())
        .pipe(less())
        .pipe(gulp.dest(destDir + '/css'));
});

For watch, I tried the built-in tool, as well as the gulp-watch plugin. Didn't notice the difference.
Plumber gives an error to the console. The command does not seem to finish execution, but watch stops working on subsequent changes to the file and you have to end it with Ctrl + C and start it again.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RasimX, 2017-02-15
@RasimX

I had the same issue. Need to remove return

gulp.task('less', function() {
    gulp.src(sourceDir + '/less/style.less')
        .pipe(plumber())
        .pipe(less())
        .pipe(gulp.dest(destDir + '/css'));
});

S
sim3x, 2015-04-26
@sim3x

gulp.task('less', function () {
  var l = less({});
  l.on('error',function(e){
    gutil.log(e);
    l.end();
  });
  return gulp.src(sourceDir + '/less/style.less')
    .pipe(l)
    .pipe(gulp.dest(destDir + '/css'));
});

https://github.com/gulpjs/gulp/issues/71

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question