Title: fix(@angular/build): disable code splitting for unit test builds by jonmarozick · Pull Request #33729 · angular/angular-cli · GitHub
Open Graph Title: fix(@angular/build): disable code splitting for unit test builds by jonmarozick · Pull Request #33729 · angular/angular-cli
X Title: fix(@angular/build): disable code splitting for unit test builds by jonmarozick · Pull Request #33729 · angular/angular-cli
Description: Fixes #33728 PR Checklist Please check to confirm your PR fulfills the following requirements: The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-commit-message-guidelines Tests for the changes have been added (for bug fixes / features) — unit-test/tests/behavior/vitest-shared-chunk-init_spec.ts; see "Other information" for how the fixture was validated red/green. Docs have been added / updated (for bug fixes / features) — N/A: the new option is internal-only and not exposed in the builder schema. PR Type What kind of change does this PR introduce? Bugfix What is the current behavior? Issue Number: #33728 Under @angular/build:unit-test with the default (jsdom) runner, an export from a module that code splitting hoisted into a shared chunk can be observed as undefined by an importing chunk — a component reading an exported const in a class-field initializer fails with TypeError: Cannot read properties of undefined (reading 'map'), in a test that never touches the runner's own API. The emitted bundles are valid ESM and the same specs pass in browser mode, so the defect is in how the Node-side module-runner path evaluates the split output, not in the bundles. Every spec file is its own entry point, so splitting hoists any module reached from more than one spec into a shared chunk behind lazy __esm initializers; importing chunks then read the export as a live ESM binding, which that path does not reliably preserve at class-field-initialization time. The full analysis — including the exact four-condition trigger set (shared chunk + cross-chunk field read + an async test callback + zone.js polyfills) isolated by single-variable toggles — is in #33728, with a minimal reproduction at https://github.com/jonmarozick/ng-shared-chunk-repro (npm install && npm test: expected 2 passed, actual 1 failed). The failure only appears once a project has more than one spec file, because a single entry point inlines everything and never splits — so a suite can pass for a long time and then break when a second spec file is added. The impact can also be silent: in a larger project on the same setup, jsdom reported 108 of 216 tests (three spec files never loaded) in half the wall-clock of browser mode. What is the new behavior? esbuild code splitting is disabled for the unit-test build only, through a new internal option (disableCodeSplitting) alongside the existing internal test-only options. Test bundles are never downloaded by a browser, so splitting has nothing to optimize here. Three small changes: application/options.ts — declare the internal option and pass it through normalizeOptions. esbuild/application-code-bundle.ts — honour it in createBrowserCodeBundleOptions, following the existing buildOptions.splitting = false precedent used for the polyfills bundle. unit-test/runners/vitest/build-options.ts — set it for the Vitest runner's build. With the change, the minimal reproduction passes (2/2) and no shared chunks are emitted for test builds. Application builds are untouched. Does this PR introduce a breaking change? No Cost: shared modules are duplicated into each spec bundle. Measured on a real 105-spec-file project via --dump-virtual-files: output files total size chunks wall splitting on 169 1.21 MB 57 30s splitting off 112 6.93 MB 0 28s Total output grows ~5.7×; test run time was unchanged. If the extra memory is a concern for very large suites, gating the option on the runner being jsdom (rather than all Vitest builds) would narrow it, since browser mode does not exhibit the bug — happy to adjust. Other information Verification. Verified by applying the equivalent change to an installed 21.2.19 @angular/build (building the CLI from source with Bazel was not available on this machine), so CI should be treated as the authoritative run: check before after minimal reproduction (jsdom) 1 failed / 1 passed 2 passed real 105-spec-file project, browser mode 1018 passed 1018 passed ng build (application build, flag unset) ok ok, still splits Regression test. unit-test/tests/behavior/vitest-shared-chunk-init_spec.ts encodes the issue's four trigger conditions: a shared const imported by two spec entries (shared chunk), a component reading it in a class-field initializer, an async test callback in that component's spec (no await needed), and zone.js in the polyfills (the setupApplicationTarget default). Earlier fixture attempts passed without the fix because their test callbacks were synchronous — zone forces async downleveling, the spec then imports the __async helper, and esbuild emits that spec entry CommonJS-wrapped with the component module behind a lazy __esm initializer, which is the shape in which the cross-chunk read fails. Since Bazel wasn't runnable on my machine, the fixture's exact file contents were validated against an installed 21.2.19 @angular/build in a fresh ng new workspace: unpatched, the container spec fails with the issue's TypeError (1 failed / 2 passed); with this change applied, all pass and no chunk-*.js is emitted. Please treat the CI run of the harness test as authoritative. One caveat encoded as a comment in the test: the failure is sensitive to inert content (a top-level console.log in either module defuses it), so the fixtures intentionally mirror the reproduction byte-for-byte rather than a paraphrase. 🤖 Generated with Claude Code
Open Graph Description: Fixes #33728 PR Checklist Please check to confirm your PR fulfills the following requirements: The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBU...
X Description: Fixes #33728 PR Checklist Please check to confirm your PR fulfills the following requirements: The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBU...
Opengraph URL: https://github.com/angular/angular-cli/pull/33729
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6b653d1e-b030-c352-ce97-c3d6e6ab31fe |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9DC8:20AA01:3A541EA:4A14E7D:6B01E852 |
| html-safe-nonce | 93960fe5610d1e8a1976ed241000a8a25b989aa05f34dfea97f290d43c22e6f2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5REM4OjIwQUEwMTozQTU0MUVBOjRBMTRFN0Q6NkIwMUU4NTIiLCJ2aXNpdG9yX2lkIjoiNDA4MDA5ODQwMzMyODA1OTQ3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e201b51a1d71180e00768a99aef4b41caca150ab73ecf14ea84eeb60986bd215 |
| hovercard-subject-tag | pull_request:4189558222 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/angular/angular-cli/pull/33729/files |
| twitter:image | https://avatars.githubusercontent.com/u/7092843?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/7092843?s=400&v=4 |
| og:image:alt | Fixes #33728 PR Checklist Please check to confirm your PR fulfills the following requirements: The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBU... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width