Skip to content

library builder: watch mode runs out of memory with many entry points #34126

Description

@thekhegay

Command

build

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

No response

Description

Found while testing #34106 cc @alan-agius4

The initial --watch build of ngwr (228 entry points) dies after 77 of them with "Reached heap limit" on the default Node heap (~4.2 GB). It's the entry point count, not the library: a generated library of 120 trivial entry points dies after 60.

Minimal Reproduction

  1. Generate a library with 120 secondary entry points, each a six-line standalone component with an inline template, no styles.
  2. ng build mylib --watch on the default Node heap.
  3. FATAL ERROR: Reached heap limit after ~60 entry points.

Peak RSS of the initial watch build under a large heap grows linearly: 30 entry points 2.3 GB, 60 4.1 GB, 120 7.6 GB, about 60 MB per entry point.

Exception or Error

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Your Environment

@angular/build built from #34106 (e1fa5796) with the repo's own bazel build
Angular CLI 22.1.8
Angular 22.1.7
Node 24.16.0
pnpm 11
macOS 25.6, 14 cores, 24 GB

Anything else relevant?

Watch compiles on the main thread and keeps node.cachedProgram for every entry point, and each one holds its own parsed copy of the .d.ts graph (per-instance sourceFiles in typescript-compilation.ts), so nothing is shared between entry points.

With --max-old-space-size=17000 it works, and incremental rebuilds are great: 70-110 ms, only the touched entry point recompiles. That's probably why your cold watch run of ngwr was fine. A shared source file cache across entry points would likely fix it; otherwise a documented heap requirement would help, since the crash itself gives no hint that entry point count is the cause.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions