webpack-stream: How do you handle errors in broken stream?

I’m trying to use plumber to handle the errors. If compilation fails during watch, plumber keeps the pipe together, but webpack watch zombies out.

var gulp = require('gulp');
var webpack = require('webpack-stream');
var path = require('path');
var plumber = require('gulp-plumber');

gulp.task('webpack-client', function() {
    return gulp.src(path.join('app/rehydrate'))
        .pipe(plumber())
        .pipe(webpack( require(path.join('../..', 'webpack.config.js'))[0] ))
        .pipe(gulp.dest(path.join('public/dist')));
});

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Comments: 24 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Has someone finally found a workaround to this issue, other than @iliakan solution to use webpack directly?

Hi Guys,

I am using the following versions of the libs and can use plumber with default settings as outlined in the first comment in order to not break the stream and the webpack watch feature when a build error occurs:

“webpack”: “^1.12.9” “webpack-stream”: “^3.0.1” “gulp-plumber”: “^1.0.1”

So there is no need anymore for custom error handling

Update: The watch task is still doing its job and every time a new build is made, but after the first error the build will be corrupt, until i restart the whole gulp task, so it’s not working smooth yet 😦

Hi guys, any solution how to solve the problem?

After the error in js, pipe is alive but there is no recompiled file.

const gulplog = require('gulplog');
const named = require('vinyl-named');
const gulp = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');
const webpackStream = require('webpack-stream');
const paths = require('../paths');

const webpack = webpackStream.webpack;
const $ = gulpLoadPlugins();
const webpackOption = require('../../webpack.config.babel');
module.exports = options => (callback) => {
  const isDevelopment = process.env.NODE_ENV.trim() === 'development';
  const jsSrcFiles = paths.src.js.files;
  const jsDestFolder = isDevelopment ? paths.build.js.folder : paths.prod.js.folder;
  let firstBuildReady = false;

  function done(err, stats) {
    firstBuildReady = true;
    if (err) { // hard error, see https://webpack.github.io/docs/node.js-api.html#error-handling
      return;  // emit('error', err) in webpack-stream
    }
    gulplog[stats.hasErrors() ? 'error' : 'info'](stats.toString({colors: true}));
  }

  /** task's options */
  const srcFiles = options.src || jsSrcFiles;
  const dest = options.dest || jsDestFolder;
  /** js assembly task */
  return gulp.src(srcFiles)
    .pipe($.plumber({
      errorHandler: $.notify.onError(err => ({
        title: 'Webpack',
        message: err.message
      }))
    }))
    .pipe(named())
    .pipe(webpackStream(webpackOption, null, done))
    .pipe($.if(!isDevelopment, $.uglify()))
    .pipe(gulp.dest(dest))
    .on('data', () => {
      if (firstBuildReady) {
        callback();
      }
    });
};

This solution is fix the issue https://github.com/shama/webpack-stream/issues/34#issuecomment-177080628

But that’s not the right way to fix.