Commit 9e99820
committed
fix(@angular/build): disable code splitting for unit test builds
Every spec file is its own entry point, so esbuild code splitting hoists any module
reached from more than one spec into a chunk shared between them. A module placed in a
shared chunk is wrapped in a lazy `__esm` initializer, so its exported value is only
assigned once that initializer runs, and importing chunks read the export as a live ESM
binding.
The unit test runners load the generated output through a module runner rather than the
browser's own ESM implementation, and that does not reliably preserve those bindings. An
importing chunk can therefore observe the export as `undefined`. A component whose class
field initializer reads a `const` exported from a module that was hoisted into a shared
chunk fails with a `TypeError`, while the same value read later, or read from within the
shared chunk itself, is correct. It only appears once a project has more than one spec
file, because a single entry point inlines everything and never splits.
Test bundles are never downloaded by a browser, so splitting has nothing to optimize
here. This disables it for the unit test build only, via an internal option, leaving
application builds unaffected.1 parent 3039776 commit 9e99820
3 files changed
Lines changed: 28 additions & 0 deletions
File tree
- packages/angular/build/src
- builders
- application
- unit-test/runners/vitest
- tools/esbuild
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
129 | 143 | | |
130 | 144 | | |
131 | 145 | | |
| |||
439 | 453 | | |
440 | 454 | | |
441 | 455 | | |
| 456 | + | |
442 | 457 | | |
443 | 458 | | |
444 | 459 | | |
| |||
475 | 490 | | |
476 | 491 | | |
477 | 492 | | |
| 493 | + | |
478 | 494 | | |
479 | 495 | | |
480 | 496 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
260 | 266 | | |
261 | 267 | | |
262 | 268 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
74 | 80 | | |
75 | 81 | | |
76 | 82 | | |
| |||
0 commit comments