The on('error')
event is still fired. However, browserify stream is a bit different from other Gulp stream. In the error handler function of browserify, you need to explicitly call this.emit("end")
An example gulp task
var browserify = require('browserify');
var gulp = require('gulp');
var source = require("vinyl-source-stream");
var reactify = require('reactify');
gulp.task('browserify', function(){
// create new bundle
var b = browserify();
// add transform if you want
b.transform(reactify);
// add file to browserify
b.add("./src/main.js");
// start bundling
return b.bundle()
.on('error', function(err){
// print the error (can replace with gulp-util)
console.log(err.message);
// end this stream
this.emit('end');
})
.pipe(source('main.js'))
// pipe other plugin here if you want
.pipe(gulp.dest('./dist'));
});
the error function handler prevents gulp from crashing, this.emit("end")
stops the current stream, not let it run to the next pipes. The event handler can also catch error in the transform plugin.
For more information, you can read here http://truongtx.me/2014/07/15/handle-errors-while-using-gulp-watch/