Skip to content

Commit 9872d43

Browse files
authored
fix(@ngtools/webpack): don't show loader errors after compilation fails (angular#7575)
1 parent b33c696 commit 9872d43

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/@ngtools/webpack/src/loader.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,14 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
602602
});
603603

604604
const result = refactor.transpile(compilerOptions);
605-
cb(null, result.outputText, result.sourceMap);
605+
606+
if (plugin.failedCompilation) {
607+
// Return an empty string to prevent extra loader errors (missing imports etc).
608+
// Plugin errors were already pushed to the compilation errors.
609+
cb(null, '');
610+
} else {
611+
cb(null, result.outputText, result.sourceMap);
612+
}
606613
})
607614
.catch(err => cb(err));
608615
} else {

packages/@ngtools/webpack/src/plugin.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export class AotPlugin implements Tapable {
6161
private _donePromise: Promise<void> | null;
6262
private _compiler: any = null;
6363
private _compilation: any = null;
64+
private _failedCompilation = false;
6465

6566
private _typeCheck = true;
6667
private _skipCodeGeneration = false;
@@ -87,6 +88,7 @@ export class AotPlugin implements Tapable {
8788
get compilerHost() { return this._compilerHost; }
8889
get compilerOptions() { return this._compilerOptions; }
8990
get done() { return this._donePromise; }
91+
get failedCompilation() { return this._failedCompilation; }
9092
get entryModule() {
9193
const splitted = this._entryModule.split('#');
9294
const path = splitted[0];
@@ -374,11 +376,14 @@ export class AotPlugin implements Tapable {
374376

375377
compiler.plugin('make', (compilation: any, cb: any) => this._make(compilation, cb));
376378
compiler.plugin('after-emit', (compilation: any, cb: any) => {
377-
this._donePromise = null;
378-
this._compilation = null;
379379
compilation._ngToolsWebpackPluginInstance = null;
380380
cb();
381381
});
382+
compiler.plugin('done', () => {
383+
this._donePromise = null;
384+
this._compilation = null;
385+
this._failedCompilation = false;
386+
});
382387

383388
compiler.plugin('after-resolvers', (compiler: any) => {
384389
// Virtual file system.
@@ -578,10 +583,13 @@ export class AotPlugin implements Tapable {
578583
.then(() => {
579584
if (this._compilation.errors == 0) {
580585
this._compilerHost.resetChangedFileTracker();
586+
} else {
587+
this._failedCompilation = true;
581588
}
582589

583590
cb();
584591
}, (err: any) => {
592+
this._failedCompilation = true;
585593
compilation.errors.push(err.stack);
586594
cb();
587595
});

0 commit comments

Comments
 (0)