docs
docs copied to clipboard
Error handling example in wiki documentation swallows warnings
From https://github.com/webpack/docs/wiki/node.js-api#error-handling
var webpack = require("webpack");
webpack({
// configuration
}, function(err, stats) {
if(err)
return handleFatalError(err);
var jsonStats = stats.toJson();
if(jsonStats.errors.length > 0)
// PREVENTS WARNINGS SHOWING
return handleSoftErrors(jsonStats.errors);
if(jsonStats.warnings.length > 0)
handleWarnings(jsonStats.warnings);
successfullyCompiled();
});
Warnings should be logged first, because some warning may be the cause of soft errors, for example "critical dependency warnings".
The return handleSoftErrors prevents warnings being shown.