catch error in runAsChild callback

This commit is contained in:
Ivan Kopeykin 2022-03-23 18:41:16 +03:00
parent 86a8bd9618
commit 449d1786c2
1 changed files with 15 additions and 2 deletions

View File

@ -545,8 +545,21 @@ class Compiler {
*/
runAsChild(callback) {
const startTime = Date.now();
this.compile((err, compilation) => {
const finalCallback = (err, entries, compilation) => {
try {
if (err) return callback(err);
callback(null, entries, compilation);
} catch (e) {
const err = new WebpackError(
`compiler.runAsChild callback error: ${e}`
);
this.parentCompilation.errors.push(err);
}
};
this.compile((err, compilation) => {
if (err) return finalCallback(err);
this.parentCompilation.children.push(compilation);
for (const { name, source, info } of compilation.getAssets()) {
@ -561,7 +574,7 @@ class Compiler {
compilation.startTime = startTime;
compilation.endTime = Date.now();
return callback(null, entries, compilation);
return finalCallback(null, entries, compilation);
});
}