Open ArnaudRinquin opened 9 years ago
I'm not sure. I don't use plumber
or the watch
option with webpack.
Closing as I don't think this is an issue with this task. If it is, let me know when an example that reproduces. Thanks!
I have the same problem.
If it is, let me know when an example that reproduces. Thanks!
I found that I had bail:true
, setting it to false fixed it. Atleast for syntax errors.
@ArnaudRinquin - Ran into this same issue. It's a gulp issue I think. There's a good explanation in https://github.com/gulpjs/gulp/issues/259. The following worked for me:
return gulp.src('webclient/index.js')
.pipe(gulpWebpack(webpackConfig, webpack))
.on('error', function handleError() {
this.emit('end'); // Recover from errors
})
.pipe(gulp.dest('webclient-dist/static'));
@shama - You might want to consider re-opening this as a documentation issue. Anyone using the watch
option will need an .on('error', ...)
handler.
@aldendaniels is everything ok after recovering? For me gulp is recovering well, watches and compiles files (judging by logs) but doesn't overwrite result files.
@nidu - sorry for not getting back. I'm no longer using webpack-stream
, but as I recall everything worked well so long as an .on('error', ...)
handler was specified.
For anyone looking at patching this, the issue seems to be on line:117 in index.js
Replacing
self.emit('error', new gutil.PluginError('webpack-stream', errorMessage));
with
console.error(errorMessage, "\x07");
Seems to fix it but i'm sure there is a better approach.
Really annoying issue. I knew that some time ago there was no such a problem and after some research found that in webpack-stream@2.1.1 it is working correctly.
So for me downgrading resolved issue and webpack-stream@2.1.1 compiles typescript and does not crash on errors, but it is sad that newer versions cant handle errors correctly
I'm having this problem as well. Working around it with .on(error, function() { ... })
for now, but out-of-the-box compatibility with plumber
would be way nicer.
I fixed it by changing:
gulp.src('app.js')
.pipe(webpack(webpackConfig, webpackSync, webpackCallback))
.on('error', (err) => {
gutil.log('WEBPACK ERROR', err);
})
.pipe(gulp.dest('dest/'));
into:
gulp.src('app.js')
.pipe(
webpack(webpackConfig, webpackSync, webpackCallback)
.on('error', (err) => {
gutil.log('WEBPACK ERROR', err);
})
)
.pipe(gulp.dest('dest/'));
+1 to @CezaryDanielNowak using .on right after the webpack-stream will allow the error to trigger but resume the watch process. Just make sure you emit and end from the catch:
gulp.task('webpack', () => {
return gulp.src(config.webpack.paths)
.pipe(plugins.vinylNamed())
.pipe(plugins.webpackStream(webpackConfig))
.on('error', function(error) {
plugins.util.log(plugins.util.colors.red(error.message));
this.emit('end');
})
.pipe(gulp.dest(config.dist + '/scripts'))
;
});
note the use of a normal function there, its to keep scope on this when running this.emit('end') using an arrow function in the .on('error') callback will break the scope of this due to lexical scoping.
After some debugging it seems that, in my setup, problem is not caused by #115 but it occurs because webpack-stream calls:
self.emit('error', new gutil.PluginError ...
two times.
After changing second "self.emit('error', new ..... " to simple log(errorMessage) everything works ok.
I suppose that error should be emitted once.
I'm facing the same issue. Is there any other solution than downgrade to 2.1.1?
Also had problem with this. (https://github.com/shama/webpack-stream/issues/18#issuecomment-220851827)
Think, not necessary emit error in watch mode.
Code below NOT working in my case, watch stiil work ok, webpack also, but pipes below(like uglify and dest) not.
.pipe(plugins.webpackStream(webpackConfig))
.on('error', function(error) {
plugins.util.log(plugins.util.colors.red(error.message));
this.emit('end');
})
I'm facing the same issue
Same issue here
@gregorskii works like a charm for me
On my setup @gregorskii 's code is still not working.
@nicholasrq:
So webpack-stream didnt crash but it didnt refresh code too
@krzysieki the same problem for me.
I have same problem I solved this problem like this:
webpack-stream/index.js:131
var compiler = webpack(config, function (err, stats) {
if (err) {
if (this.watcher) this.watcher.close();
self.emit('error', new gutil.PluginError('webpack-stream', err));
}
var jsonStats = stats.toJson() || {};
var errors = jsonStats.errors || [];
gulpfiles.js
function webpackError() {
this.emit('end');
}
var stream = webpackStream(webpackConfig);
gulp.task('webpack', (f) => {
return gulp.src(assets_path)
.pipe(named((f) => {
var match = /(.+)\.(.+)$/.exec(f.relative);
return match[1];
}))
.pipe(stream)
.on('error', webpackError)
.pipe(gulp.dest(assets_output));
});
gulp.watch(assets_path, ['webpack']);
It just stop watch and rerun pipe if it broken.
I think webpack-stream should be not break pipe in watch mode. so above code is temporary solution.
I have the same problem as @krzysieki
-> Save, webpack compiles fine -> Save with a syntax error, webpack outputs error, "Cannot find module" error in browser -> Fix error, save, webpack says it's compiled fine, but file is not updated and missing module error persists
So basically the watch works fine as long as I never save with an error. If I do, I have to relaunch the gulp script.
+1
With a little help of @gkiely's comment, I found the root of the problem:
webpack-stream
emits an error
event. error
events ondata
handler. error
event has occurred.To solve this issue, webpack-stream
should not emit an error
event on compilation error. At least not when watch
ing. PR #126 should solve this.
I just tested the patch in https://github.com/shama/webpack-stream/pull/126 and it takes care of the issue while running the watcher nicely!
@shama could you please merge it and update the npm package?
@TSMMark How could the files be written if there was an error? You have to have a successful parse to be able to emit a file.
What you want is for the watch to not be broken when you have a parse error, but to instead see the error in console output. Then you fix the error, and the following compilation will be successful and the file will be written.
I meant subsequent builds in my watch task. If it errored one time I would have to terminate the watch and start it over.
To fix use "webpack-stream": "github:jeroennoten/webpack-stream#patch-1"
return gulp.src(paths.scripts.src, {sourcemaps: true})
.pipe(
webpack(webpackConfig)
.on('error', (err) => {
console.log(err.message);
this.emit('end'); // Recover from errors
})
);
Hello,
I am using
webpack
andgulp
to build acoffee-script
app usingwebpack
watch
option.Any
coffee-loader
error, such as a syntax error, will just crashwebpack
along withgulp
.Using
plumber
or anything to catch the error will preventgulp
from crashing but won't keepwebpack
alive.How can we fix that?