Error handling for a watchify recepie
I would like to see a working example for error handling for fast-browserify-builds-with-watchify. Now it just crashes for me on error.
Thanks!
It's quite tricky to get it working without crashing. Check out my Gulpfile.
Check out my task:
var gulp = require('gulp'),
gutil = require('gulp-util'),
watchify = require("watchify"),
source = require('vinyl-source-stream');
livereload = require('gulp-livereload');
/**
* Create a single file app.js
*/
module.exports = function(server) {
// Concatenate your app and build an app.js
var bundler = watchify('./app/scripts/core/core.js');
bundler.on('update',rebundle);
function rebundle(file) {
if(file) {
file.map(function (fileName) {
gutil.log('File updated', gutil.colors.yellow(fileName));
});
}
return bundler
.bundle({
debug: (gutil.env.type !== 'prod')
})
.on("error", function(err) {
gutil.log("Browserify error:", err);
})
.pipe(source("app.js"))
.pipe(gulp.dest('./build/js'))
.pipe(livereload(server));
}
return rebundle();
};
So, no more crashes but a log with your error cf :

Finding this no longer works with newest version of watchify/browserify.
:-1: this no longer works :-(
@FlorentD, try to add this.emit('end');
.on('error', function (err) {
gutil.log(err.toString());
this.emit('end');
})
@FlorentD @alferov Maybe just callback? For me it works well
.pipe(...)
.on('error', done)
this.emit('end') was the key. Thanks @alferov