This is very common with other compiler toolchains like GCC via -Werror.
It's very useful for scenarios where you are required to follow strict guidelines and want to treat builds with warnings as errors and return a non-zero status code.
I couldn't find anything in Webpack's docs about this -- is it possible via the CLI?
Thanks!
(Latest version of Webpack v4.41.5 as of the time of writing this question)
There's an NPM package that does this for you: Webpack - Warnings To Errors
There are a couple of things you can configure on your own:
stats: {
    logging: 'info', //  errors, warnings, and info messages
    warnings: true
},
output: {
    strictExportPresence: true // will throw error if import is missing, usually warning
}
Otherwise, create your own function for this:
if (compilation.warnings.length > 0) {
  compilation.errors = compilation.errors.concat(compilation.warnings);
  compilation.warnings = [];
}
compilation.children.forEach((child) => {
  if (child.warnings.length > 0) {
    child.errors = child.errors.concat(child.warnings);
    child.warnings = [];
  }
});
For Webpack 5 you can use the CLI flag --fail-on-warnings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With