Skip to content

fix(@ngtools/webpack): gracefully show error when compiling broken co… #15244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,32 @@ describe('Browser Builder AOT', () => {
expect(logs.join()).toContain('WARNING in Invalid selector');
await run.stop();
});

it('shows error when component stylesheet contains SCSS syntax error', async () => {
const overrides = {
aot: true,
};

host.replaceInFile(
'src/app/app.component.ts',
'app.component.css',
'app.component.scss',
);

host.writeMultipleFiles({
'src/app/app.component.scss': `
.foo {
`,
});

const logger = new logging.Logger('');
const logs: string[] = [];
logger.subscribe(e => logs.push(e.message));

const run = await architect.scheduleTarget(targetSpec, overrides, { logger });
const output = await run.result;
expect(output.success).toBe(false);
expect(logs.join()).toContain(`Expected "}".`);
await run.stop();
});
});
8 changes: 6 additions & 2 deletions packages/ngtools/webpack/src/resource_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ export class WebpackResourceLoader {
// Compile and return a promise
return new Promise((resolve, reject) => {
childCompiler.compile((err: Error, childCompilation: any) => {
if (err) {
reject(err);

return;
}

// Resolve / reject the promise
const { warnings, errors } = childCompilation;

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

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