diff --git a/packages/webpack/src/ember-webpack.ts b/packages/webpack/src/ember-webpack.ts index 4b236ce28..1ce633e49 100644 --- a/packages/webpack/src/ember-webpack.ts +++ b/packages/webpack/src/ember-webpack.ts @@ -443,27 +443,29 @@ const Webpack: PackagerConstructor = class Webpack implements Packager private runWebpack(webpack: webpack.MultiCompiler): Promise { return new Promise((resolve, reject) => { webpack.run((err, stats) => { - if (err) { - if (stats) { + try { + if (err) { + if (stats) { + this.consoleWrite(stats.toString()); + } + throw err; + } + if (!stats) { + // this doesn't really happen, but webpack's types imply that it + // could, so we just satisfy typescript here + throw new Error('bug: no stats and no err'); + } + if (stats.hasErrors()) { + // the typing for MultiCompiler are all foobared. + throw this.findBestError(flatMap((stats as any).stats, s => s.compilation.errors)); + } + if (stats.hasWarnings() || process.env.VANILLA_VERBOSE) { this.consoleWrite(stats.toString()); } - reject(err); - return; - } - if (!stats) { - // this doesn't really happen, but webpack's types imply that it - // could, so we just satisfy typescript here - throw new Error('bug: no stats and no err'); - } - if (stats.hasErrors()) { - // the typing for MultiCompiler are all foobared. - reject(this.findBestError(flatMap((stats as any).stats, s => s.compilation.errors))); - return; - } - if (stats.hasWarnings() || process.env.VANILLA_VERBOSE) { - this.consoleWrite(stats.toString()); + resolve(stats.toJson()); + } catch (e) { + reject(e); } - resolve(stats.toJson()); }); }); }