| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
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.
Sorry, something went wrong.
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
|
This PR was merged into the repository. The changes were merged into the following branches: |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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