From 00421325fe317ad6538bb72f22bec60fd3b51e6e Mon Sep 17 00:00:00 2001 From: Valerii Sidorenko Date: Thu, 18 Jul 2024 16:05:44 +0200 Subject: [PATCH] fix(worker-lodaer): correctly return errors from loader (#151) --- src/common/webpack/worker/worker-loader.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/webpack/worker/worker-loader.ts b/src/common/webpack/worker/worker-loader.ts index 9abf329..79e96dc 100644 --- a/src/common/webpack/worker/worker-loader.ts +++ b/src/common/webpack/worker/worker-loader.ts @@ -72,16 +72,18 @@ export const pitch: webpack.PitchLoaderDefinitionFunction = function (request) { const cb = this.async(); workerCompiler.compile((err, compilation) => { - if (!compilation) { - return undefined; + if (compilation) { + workerCompiler.parentCompilation?.children.push(compilation); } - workerCompiler.parentCompilation?.children.push(compilation); - if (err) { return cb(err); } + if (!compilation) { + return cb(new Error('Child compilation failed')); + } + if (compilation.errors && compilation.errors.length) { const errorDetails = compilation.errors .map((error) => { @@ -98,7 +100,7 @@ export const pitch: webpack.PitchLoaderDefinitionFunction = function (request) { const cacheIdent = request; const objectToHash = compilation.assets[filename]; if (!objectToHash) { - throw new Error(`Asset ${filename} not found in compilation`); + return cb(new Error(`Asset ${filename} not found in compilation`)); } const cacheETag = cache.getLazyHashedEtag(objectToHash);