gulp icon indicating copy to clipboard operation
gulp copied to clipboard

Error handling for a watchify recepie

Open samvasko opened this issue 12 years ago • 7 comments

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!

samvasko avatar May 24 '14 14:05 samvasko

It's quite tricky to get it working without crashing. Check out my Gulpfile.

PavelGavlik avatar Jun 24 '14 20:06 PavelGavlik

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 :

capture du 2014-06-10 15 01 36

dhoko avatar Jun 27 '14 07:06 dhoko

Finding this no longer works with newest version of watchify/browserify.

builtbylane avatar Feb 18 '15 22:02 builtbylane

:-1: this no longer works :-(

FlorentD avatar Jul 03 '15 16:07 FlorentD

@FlorentD, try to add this.emit('end');

.on('error', function (err) {
  gutil.log(err.toString());
  this.emit('end');
})

alferov avatar Jul 03 '15 16:07 alferov

@FlorentD @alferov Maybe just callback? For me it works well

.pipe(...)
.on('error', done)

TrySound avatar Jul 03 '15 17:07 TrySound

this.emit('end') was the key. Thanks @alferov

pixelprodev avatar Sep 15 '15 01:09 pixelprodev