Skip to content

Commit c18ba5f

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
fix(@ngtools/webpack): gracefully show error when compiling broken component styles
Fixes #15240
1 parent fd2c264 commit c18ba5f

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/angular_devkit/build_angular/test/browser/aot_spec_large.ts

+28
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,32 @@ describe('Browser Builder AOT', () => {
6363
expect(logs.join()).toContain('WARNING in Invalid selector');
6464
await run.stop();
6565
});
66+
67+
it('shows error when component stylesheet contains SCSS syntax error', async () => {
68+
const overrides = {
69+
aot: true,
70+
};
71+
72+
host.replaceInFile(
73+
'src/app/app.component.ts',
74+
'app.component.css',
75+
'app.component.scss',
76+
);
77+
78+
host.writeMultipleFiles({
79+
'src/app/app.component.scss': `
80+
.foo {
81+
`,
82+
});
83+
84+
const logger = new logging.Logger('');
85+
const logs: string[] = [];
86+
logger.subscribe(e => logs.push(e.message));
87+
88+
const run = await architect.scheduleTarget(targetSpec, overrides, { logger });
89+
const output = await run.result;
90+
expect(output.success).toBe(false);
91+
expect(logs.join()).toContain(`Expected "}".`);
92+
await run.stop();
93+
});
6694
});

packages/ngtools/webpack/src/resource_loader.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ export class WebpackResourceLoader {
9999
// Compile and return a promise
100100
return new Promise((resolve, reject) => {
101101
childCompiler.compile((err: Error, childCompilation: any) => {
102+
if (err) {
103+
reject(err);
104+
105+
return;
106+
}
107+
102108
// Resolve / reject the promise
103109
const { warnings, errors } = childCompilation;
104110

@@ -114,8 +120,6 @@ export class WebpackResourceLoader {
114120
.join('\n');
115121

116122
reject(new Error('Child compilation failed:\n' + errorDetails));
117-
} else if (err) {
118-
reject(err);
119123
} else {
120124
Object.keys(childCompilation.assets).forEach(assetName => {
121125
// Add all new assets to the parent compilation, with the exception of

0 commit comments

Comments
 (0)