FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(@angular/build): ignore side-effect annotations in unit test builds by alan-agius4 · Pull Request #33917 · angular/angular-cli · GitHub

fix(@angular/build): ignore side-effect annotations in unit test builds - #33917

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix-unit-test-barrel-side-effects
Aug 25, 2026
Merged

fix(@angular/build): ignore side-effect annotations in unit test builds#33917
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix-unit-test-barrel-side-effects

Conversation

Copy link
Copy Markdown
Collaborator

In libraries built with ng-packagr, package.json typically specifies "sideEffects": false so consumer applications can tree-shake unused code. However, when executing unit tests through @angular/build:unit-test, the test builder bundles workspace library source directly (via tsconfig paths).

Because esbuild tree-shaking respects "sideEffects": false annotations in the enclosing package.json, bundling multiple spec entry points without splitting can cause esbuild to prune module bodies (such as component definitions) from multi-level export * barrel graphs while retaining namespace re-export accessors. At runtime, accessing the exported symbols evaluates to undefined, causing failures such as TypeError: Cannot read properties of undefined (reading 'ɵcmp').

Test bundles are executed locally in memory and never distributed over the wire, so side-effect annotations and pure call pruning are not required. Setting ignoreAnnotations: true when disableCodeSplitting is enabled ensures that statically reachable barrel exports in workspace code are retained without affecting production application or package builds.

Closes #33910

alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Aug 25, 2026
alan-agius4 requested a review from clydin August 25, 2026 13:30

gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request addresses an issue where statically-referenced barrel module bodies were incorrectly elided by esbuild in unit test builds when package.json had "sideEffects": false. This is resolved by setting buildOptions.ignoreAnnotations to true for unit test builds. A corresponding Vitest integration test has been added to prevent regressions. Feedback on the test suggests formatting the modified tsconfig.json with indentation for easier debugging.

In libraries built with ng-packagr, `package.json` typically specifies
`"sideEffects": false` so consumer applications can tree-shake unused code.
However, when executing unit tests through `@angular/build:unit-test`, the
test builder bundles workspace library source directly (via tsconfig paths).

Because esbuild tree-shaking respects `"sideEffects": false` annotations in the
enclosing `package.json`, bundling multiple spec entry points without splitting
can cause esbuild to prune module bodies (such as component definitions) from
multi-level `export *` barrel graphs while retaining namespace re-export
accessors. At runtime, accessing the exported symbols evaluates to `undefined`,
causing failures such as `TypeError: Cannot read properties of undefined (reading 'ɵcmp')`.

Test bundles are executed locally in memory and never distributed over the wire,
so side-effect annotations and pure call pruning are not required. Setting
`ignoreAnnotations: true` when `disableCodeSplitting` is enabled ensures that
statically reachable barrel exports in workspace code are retained without
affecting production application or package builds.

Closes angular#33910
alan-agius4 force-pushed the fix-unit-test-barrel-side-effects branch from e1a935d to 9f33518 Compare August 25, 2026 13:34
alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 25, 2026
alan-agius4 merged commit 4d0be68 into angular:main Aug 25, 2026
38 of 40 checks passed
alan-agius4 deleted the fix-unit-test-barrel-side-effects branch August 25, 2026 14:24

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unit-test builder: "sideEffects": false elides statically-referenced barrel modules, component reads as undefined in TestBed

2 participants


Back | FazBrowse Home | New Git URL