Skip to content

Commit 8aeffa1

Browse files
fix: restore module error guard in after-compile
Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/72a9d59f-c15a-451b-a293-48ee4ddae4e6 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com>
1 parent 8fe5821 commit 8aeffa1

2 files changed

Lines changed: 1096 additions & 781 deletions

File tree

src/after-compile.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,15 @@ function provideErrorsToWebpack(
266266
compilation.compiler.context
267267
);
268268

269-
formattedErrors.forEach(error => {
270-
if (module.addError) {
271-
module.addError(error);
272-
} else {
273-
module.errors.push(error);
274-
}
275-
});
269+
if (!moduleHasErrors(module, instance.isWebpack5)) {
270+
formattedErrors.forEach(error => {
271+
if (module.addError) {
272+
module.addError(error);
273+
} else {
274+
module.errors.push(error);
275+
}
276+
});
277+
}
276278

277279
compilation.errors.push(...formattedErrors);
278280
});
@@ -334,13 +336,15 @@ function provideSolutionErrorsToWebpack(
334336
compilation.compiler.context
335337
);
336338

337-
formattedErrors.forEach(error => {
338-
if (module.addError) {
339-
module.addError(error);
340-
} else {
341-
module.errors.push(error);
342-
}
343-
});
339+
if (!moduleHasErrors(module, instance.isWebpack5)) {
340+
formattedErrors.forEach(error => {
341+
if (module.addError) {
342+
module.addError(error);
343+
} else {
344+
module.errors.push(error);
345+
}
346+
});
347+
}
344348

345349
compilation.errors.push(...formattedErrors);
346350
});
@@ -572,3 +576,10 @@ function isTSLoaderModuleError(error: any, loaderOptions: LoaderOptions) {
572576
error?.error?.details === source
573577
);
574578
}
579+
580+
function moduleHasErrors(module: webpack.Module, isWebpack5: boolean) {
581+
return isWebpack5
582+
? Array.from(module.getErrors!() || []).length > 0
583+
: (((module as any).errors as webpack.WebpackError[] | undefined) || [])
584+
.length > 0;
585+
}

0 commit comments

Comments
 (0)