Skip to content

ng build crashes with heap corruption (exit code -1073740940) on Node.js 24 during Angular library compilation #32234

@cool-akash

Description

@cool-akash

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

angularVersion = "18.2.5" nodeVersion = "20.18.0"

Description

After migrating to Angular CLI 20.3.6 and Node.js 24.0.0 When building an Angular library using ng build --configuration production library, the build process crashes sporadically with exit code -1073740940 (0xC0000374) - a Windows heap corruption error.

The crash occurs during partial compilation mode, specifically when building entry points. The error is intermittent/sporadic - the same build may succeed or fail randomly without any code changes

Minimal Reproduction

I am currently working on production code, so I cannot share the full repository.
However, I am able to suggest a minimal reproduction, as the issue appears to be sporadic and reproducible under certain conditions.

The Angular library build intermittently crashes during a production build, even when heap memory is increased.
Minimal Reproduction Steps

Step 1: Create a new Angular workspace with a library
npx @angular/[email protected] new repro-app --no-create-application
cd repro-app
npx ng generate library my-lib

Step 2: Add dependencies
npm install echarts@^5.5.1 d3@^7.9.0 --save
npm install @types/d3@^7.4.3 --save-dev

Step 3: Generate multiple components (PowerShell)
1..50 | ForEach-Object { npx ng generate component "comp$_" --project=my-lib }

Step 4: Ensure public_api.ts exists

Create or verify the following file:

projects/my-lib/src/public_api.ts

Step 5: Build the library repeatedly
npx ng build my-lib --configuration production

➡️ Run the build 5 times.
➡️ The crash occurs sporadically, not on every run.

Step 6: (Optional) Build with increased heap memory
node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build my-lib --configuration production

Additional:
The project still uses the legacy library builder:

"builder": "@angular-devkit/build-angular:ng-packagr"
I have not migrated to standalone components (standalone: false is still in use).

⚠️ Increasing heap memory does not consistently prevent the crash.

Expected Behavior

The library should build successfully and consistently in production mode.

Repeated builds should not result in random crashes.

Actual Behavior

The build intermittently fails with a crash.

The issue is non-deterministic and may succeed or fail across runs using the same code and environment.

Increasing Node.js heap size does not reliably resolve the problem.

Exception or Error

Error MSB3073: The command "ng build --configuration production library" exited with code -1073740940


The build crashes sporadically with exit code -1073740940 (0xC0000374) - Windows heap corruption error. The crash:

Occurs randomly (same code may build successfully or fail)
Happens during partial compilation mode
Cannot be fixed by increasing Node.js heap memory (--max-old-space-size=8192)
Persists across Node.js versions 20.x, 22.x, and 24.x



Error Output
> ng build --configuration production library

Building Angular Package

------------------------------------------------------------------------------
Building entry point '@my-lib/common-ui'
------------------------------------------------------------------------------
- Compiling with Angular sources in partial compilation mode.
✔ Compiling with Angular sources in partial compilation mode.

Error MSB3073: The command "ng build --configuration production library" exited with code -1073740940

Your Environment

OS: Windows 10/11 (64-bit)
Node.js: 24.0.0 (also tested with 22.x and 20.x)
npm: 11.3.0
Angular CLI: 20.3.6
@angular-devkit/build-angular: 20.3.6
ng-packagr: 20.3.2
esbuild: 0.25.9 (transitive dependency)
TypeScript: 5.8.3

Anything else relevant?

Things Attempted (Did Not Work)

  1. Increased Node.js heap memory to 8GB (--max-old-space-size=8192)
  2. Switched to Node.js 24 (as per Angular documentation)
  3. Switched to Node.js 22 LTS
  4. Deleted node_modules and performed clean reinstall
  5. Cleared .angular cache directory
  6. Disabled Angular CLI cache
  7. Disabled TypeScript declaration maps ("declarationMap": false)
  8. Disabled source maps ("sourceMap": false)
  9. Disabled incremental compilation ("incremental": false)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions