Skip to content

Commit

Permalink
Add stacktrace to error message from childCompilation.errors
Browse files Browse the repository at this point in the history
I was had an error that was thrown in my webpack.config.ts that was causing childCompilation to fail. But I didn't know it was an error thrown in my webpack.config.ts because child-compiler.js didn't include the stack trace in the error message.

The stack trace I got ended at line 122 in node_modules\html-webpack-plugin\lib\child-compiler.js. So I fiddled with that to make it output the inner error stack trace and then I got the actual place of the error.
  • Loading branch information
samal-rasmussen authored and jantimon committed Jun 15, 2020
1 parent d051f5f commit 85accfa
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/child-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,16 @@ class HtmlWebpackChildCompiler {
}
// Reject the promise if the childCompilation contains error
if (childCompilation && childCompilation.errors && childCompilation.errors.length) {
const errorDetails = childCompilation.errors.map(error => error.message + (error.error ? ':\n' + error.error : '')).join('\n');
const errorDetails = childCompilation.errors.map(error => {
let message = error.message;
if (error.error) {
message += ':\n' + error.error;
}
if (error.stack) {
message += '\n' + error.stack;
}
return message;
}).join('\n');
reject(new Error('Child compilation failed:\n' + errorDetails));
return;
}
Expand Down

0 comments on commit 85accfa

Please sign in to comment.