Repository navigation
Description
Command
test
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
22.1.4
Description
Since @angular/build 22.1.5, running the unit-test builder (Vitest runner) with coverage enabled on a large workspace shows the following pattern on our biggest libraries:
- all tests complete normally (e.g. 27 spec files / 400 tests in ~35 s),
- then the process keeps running at 100–160 % CPU and ~3–4 GB RSS with no output for more than 15 minutes — it looks like a hang. It is in fact the V8 coverage collection/remap phase.
On 22.1.4 the exact same target completes in 57 s end to end.
We bisected it to 22.1.5's fix(@angular/build): disable code splitting for unit test builds (unit-test/runners/vitest/build-options.ts now forces disableCodeSplitting: true). Our understanding of the mechanism: every spec file being an entry point, the test build now produces a single monolithic chunk containing the whole transitive module graph of the project (in our workspace: hundreds of internal libraries), and @vitest/coverage-v8 has to remap the source map of that entire chunk for every project, even though the coverage thresholds / report only concern the project's own files. With code splitting, the remap work was proportional to what each spec actually loaded.
Confirmed by re-applying disableCodeSplitting: false locally (pnpm patch): same project, same 22.1.6, 39 s end to end, identical coverage numbers.
Things we tried that do not help:
coverage.include: ['<projectRoot>/**']in the Vitest runner config → coverage drops to 0 %: the filter seems to be applied to the bundled chunk paths before source-map remapping, so real hits are discarded and only unloaded files are reported (withFailed to parse ... README.md/component.html. Excluding it from coverage.warnings for every non-JS file in the project).- Excluding
**/*.htmlfrom coverage → no measurable effect. - 22.1.6 → same behaviour.
We understand the motivation of the change (live ESM bindings read across a lazily-initialised shared chunk), but as it stands the trade-off makes coverage unusable on large workspaces: with 186 projects our CI job went from ~15 min to jobs timing out on the largest libraries. Possible directions:
- expose the behaviour as a builder option (e.g.
codeSplitting: booleanon theunit-testbuilder, defaulting to the currentfalse), so workspaces that never hit the live-binding issue can opt back in; - or keep the monolithic build but scope the V8 coverage remap to the files that match
coverage.include/ the project root after remapping (i.e. remap only the source-map segments that resolve to included sources); - or emit the shared modules as eagerly-initialised chunks instead of disabling splitting altogether.
Minimal Reproduction
We do not have a small public reproduction yet — the effect is proportional to the size of the transitive module graph. Characteristics of the workspace that reproduces it reliably:
- Nx 23.1.1 monorepo, ~5 100 non-spec TypeScript files under
libs/, 186 projects with atesttarget; - tests run through
@nx/angular:unit-test(which delegates to the@angular/buildunit-testbuilder), Vitest runner,coverage: true, providerv8, reporterslcovonly+cobertura, thresholds scoped to<projectRoot>/**; - the affected library has 27 spec files / 400 tests and its lcov report lists 462 source files (88 of which belong to the library itself, the rest being transitive internal libraries).
Timings on the same machine (14 CPU, container, Node 22.22.3), same project, --configuration=ci (coverage on):
@angular/build |
tests | coverage phase | total |
|---|---|---|---|
| 22.1.4 | ~35 s | ~20 s | 57 s |
| 22.1.6 | ~35 s | > 15 min (killed) | — |
22.1.6 + disableCodeSplitting: false (local patch) |
~35 s | ~5 s | 39 s |
Without coverage, 22.1.6 completes in ~30 s, so the tests themselves are unaffected. I am happy to run additional diagnostics (e.g. --dumpVirtualFiles, CPU profile of the coverage phase) or to try a patch.
Exception or Error
No exception — the process stays busy (100–160 % CPU, 3–4 GB RSS) with no output after the last test result. Killing it after 15+ minutes yields no report.
Your Environment
Angular CLI: 22.1.6
Node: 22.22.3
Package Manager: pnpm 11.24.0
OS: linux x64
@angular/build: 22.1.6 (regression introduced in 22.1.5)
@angular/core: 22.1.3
@angular/compiler-cli: 22.1.3
vitest: 4.1.11
@vitest/coverage-v8: 4.1.11
typescript: 6.0.3
jsdom: 30.0.1
nx / @nx/angular: 23.1.1
Anything else relevant?
No response
Activity
fix(@angular/build): re-enable code splitting for unit tests
fix(@angular/build): re-enable code splitting for unit tests
fix(@angular/build): re-enable code splitting for unit tests
fix(@angular/build): re-enable code splitting for unit tests
fix(@angular/build): re-enable code splitting for unit tests
fix(@angular/build): re-enable code splitting for unit tests
fix(@angular/build): re-enable code splitting for unit tests
fix(@angular/build): re-enable code splitting for unit tests
fix(@angular/build): re-enable code splitting for unit tests
robsonbittencourt commentedon Aug 28, 2026
Confirming this on a much smaller workspace, with two data points that may help: it also happens with
@vitest/coverage-istanbul(not just v8), and here it is a hard OOM crash, not only a slowdown.Repo (public, reproduces as-is): https://github.com/robsonbittencourt/vgc-multicalc
Setup: single-application workspace — no internal libraries — 167 spec files / 338 non-spec source files / ~213k lines,
@angular/build:unit-testwith the Vitest runner,provider: "istanbul".Version bisection. Only
@angular/buildwas changed between runs;@angular/cli22.1.6, the framework,vitest,jsdomand the coverage provider stayed fixed. Same suite, same machine,ng test --coverage --watch=false:@angular/buildWithout coverage, 22.1.6 runs the suite fine in ~97 s, so it is specific to the coverage path.
This matches your bisection:
disableCodeSplitting: trueis absent fromsrc/builders/unit-test/in the 22.1.4 tarball and present in both 22.1.5 and 22.1.6.The crash on 22.1.6:
Memory sampled every 2 s (sum of RSS across
ng test+ vitest workers + esbuild):Peak single process 7.7 GB, peak total 11.3 GB, on a machine with ~24 GB available — the ceiling being hit is V8's default ~4.3 GB heap, not host memory.
Two things that may narrow the mechanism down:
Switching to
@vitest/coverage-istanbuldoes not avoid it. In Code splitting change introduced in @angular/build@22.1.5 breaks vitest cobertura report #33938 the suggested workaround was moving offcoverage-v8; this workspace has used istanbul throughout and still OOMs. So the cost is not confined to V8 byte-offset remapping — the istanbul path hits it too, which points at the monolithic chunk itself rather than the remapping strategy.The amplifier here is file size, not project count. There are no internal libraries to fan out over. What this app does have is a few large data-only modules — plain object literals, no branches:
With code splitting disabled these land in the single shared chunk every spec pulls in. That suggests a minimal repro could be built from one generated multi-MB data file plus a handful of specs, which would be far easier to package than a 186-project monorepo.
Possibly related, same version jump: on 22.1.5/22.1.6
vi.resetModules()no longer recycles modules for theunit-testbuilder. A spec that callsvi.resetModules()inbeforeEachand thenawait import("./some-module")gets the module instance evaluated in the first test, so a module readinglocalStorageat import time keeps its initial value for the rest of the file. On 22.1.4 the same spec passes (167/167); on 22.1.6 it fails (166/167). I have not verified whether this shares a root cause with the code-splitting change — happy to file it separately if it is unrelated.A
codeSplittingbuilder option as you proposed would work for us. Happy to test a patch, or to put together that minimal repro if it would help.fix(@angular/build): add splitting option to unit-test builder
fix(@angular/build): add splitting option to unit-test builder
fix(@angular/build): add splitting option to unit-test builder
angular-automatic-lock-bot commentedon Oct 20, 2026
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.