Skip to content

Commit 03fc4af

Browse files
cexbrayatclydin
authored andcommitted
refactor(@angular-devkit/build-angular): mention how to disable the warning for commonjs dependencies
The current message clearly mentions which dependencies are CommonJS ones, but doesn't point out how to get rid of the warning if nothing can be done. This commit adds a mention of `allowedCommonJsDependencies` in the warning to help developers (as we do for `versionMismatch` for example).
1 parent f172379 commit 03fc4af

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/plugins/common-js-usage-warn-plugin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export class CommonJsUsageWarnPlugin {
8282
// will require CommonJS libraries for live reloading such as 'sockjs-node'.
8383
if (mainIssuer?.name === 'main' && !issuer?.userRequest?.includes('webpack-dev-server')) {
8484
const warning = `${issuer?.userRequest} depends on ${rawRequest}. CommonJS or AMD dependencies can cause optimization bailouts.\n` +
85-
'For more info see: https://web.dev/commonjs-larger-bundles';
85+
'For more info see: https://web.dev/commonjs-larger-bundles\n' +
86+
`To disable this warning add "${rawRequest}" to the "allowedCommonJsDependencies" option under "build" options in "angular.json".`;
8687

8788
// Avoid showing the same warning multiple times when in 'watch' mode.
8889
if (!this.shownWarnings.has(warning)) {

packages/angular_devkit/build_angular/src/browser/specs/common-js-warning_spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('Browser Builder commonjs warning', () => {
3737
expect(output.success).toBe(true);
3838
const logMsg = logs.join();
3939
expect(logMsg).toMatch(/WARNING in.+app\.component\.ts depends on bootstrap\. CommonJS or AMD dependencies/);
40+
expect(logMsg).toMatch(/To disable this warning add "bootstrap" to the "allowedCommonJsDependencies" option/);
4041
expect(logMsg).not.toContain('jquery', 'Should not warn on transitive CommonJS packages which parent is also CommonJS.');
4142
await run.stop();
4243
});

0 commit comments

Comments
 (0)