browserify / watchify

watch mode for browserify builds
Other
1.79k stars 203 forks source link

Watchify breaks error handling #350

Closed Liero closed 6 years ago

Liero commented 6 years ago

With browserify this works:

bundler.bundle()
    .pipe(source(bundleFileName))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
        // Add transformation tasks to the pipeline here.
        .pipe(uglify())
        .on('error', gutil.log)
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest(dest + '/scripts'));

but when I includude wachify plugin, the error callbacks are not called.

bundler.plugin(watchify);

I believe this is an unexpected behavior.

Current workaround is to include on('error', ..) directly afrer bundler.bundle()

bundler.bundle()
    .on('error', gutil.log)
    .pipe(source(bundleFileName))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
        // Add transformation tasks to the pipeline here.
        .pipe(uglify())
        .on('error', gutil.log)
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest(dest + '/scripts'));
menzow commented 6 years ago

Within the scope of watchify this behaviour is not unexpected. The issue is that you don't handle events and that node does not forward error events.

You can find a great explanation here: https://stackoverflow.com/questions/21771220/error-handling-with-node-js-streams?answertab=votes#tab-top

This behaviour was also explained in this browserify issue: https://github.com/browserify/browserify/issues/1487#issuecomment-173357516