Skip to content

Commit

Permalink
Do not crash on errors in webpack 5 (#481)
Browse files Browse the repository at this point in the history
* Do not crash during error reporting in WP5

* Change files
  • Loading branch information
christiango authored Oct 22, 2020
1 parent cdd14a8 commit 4e977b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "patch",
"comment": "Do not crash reporting errors in Webpack 5",
"packageName": "just-scripts",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-10-22T14:40:17.118Z"
}
12 changes: 9 additions & 3 deletions packages/just-scripts/src/tasks/webpackTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ export function webpackTask(options?: WebpackTaskOptions): TaskFunction {

if (options && options.outputStats) {
const statsFile = options.outputStats === true ? 'stats.json' : options.outputStats;
fs.writeFileSync(statsFile, JSON.stringify(stats.toJson(), null, 2));
fs.writeFileSync(statsFile, JSON.stringify(stats!.toJson(), null, 2));
}

if (err || stats.hasErrors()) {
logger.error(stats.toString({ children: webpackConfigs.map((c) => c.stats) }));
reject(`Webpack failed with ${stats.toJson('errors-only').errors.length} error(s).`);
// Stats may be undefined the the case of an error in Webpack 5
if (stats) {
logger.error(stats.toString({ children: webpackConfigs.map((c) => c.stats) }));
reject(`Webpack failed with ${stats.toJson('errors-only').errors.length} error(s).`);
} else {
logger.error(err.toString());
reject(`Webpack failed with error(s).`);
}
} else {
resolve();
}
Expand Down

0 comments on commit 4e977b7

Please sign in to comment.