Turbo87 / webpack-notifier

webpack + node-notifier = build status system notifications
ISC License
306 stars 41 forks source link

Yarn watch dies on warning after first pass #44

Closed dharkness closed 6 years ago

dharkness commented 6 years ago

I'm using this as part of Laravel Mix 2.1.11, but I've isolated the problem to this plugin, the Webpack Stats object, or the former's use of the latter. Compiling our JS/SASS produces a warning on the initial run of yarn watch due to an image URL it thinks doesn't exist which is fine. Changing a SASS file causes the build to rerun, but this time the process halts with a type error "trying to access 'module' of undefined."

Line 28 sees that stats.hasWarnings() returns true, and line 29 sets error to the first element of the stats.compilation.warnings array, but this array is empty. Line 42 then tries to access error.module which kills the process.

I inserted the following before line 39:

// Fix "yarn watch"
if (!error) {
    console.log(stats.hasErrors());
    console.log(stats.compilation.errors);
    console.log(stats.hasWarnings());
    console.log(stats.compilation.warnings);
    return 'Build successful';
}

This lets the build proceed after printing this:

false
[]
true
[]

Are there other sources of warnings besides the compilation object? If not, it looks like Webpack may actually be at fault here, but I don't know the Webpack codebase or API at all. Either way, it probably makes sense to check that error is truthy before accessing its properties.

I went with this solution for now before line 39:

// Fix "yarn watch"
if (!error) {
    return 'Unknown ' + (stats.hasErrors() ? 'error' : 'warning');
}
dharkness commented 6 years ago

I just noticed this at the top of the output which convinces me the problem is with Webpack because even they get it wrong:

WARNING  Compiled with 0 warnings

:)