Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@leosvelperez
Copy link
Member

Current Behavior

When building Angular libraries with ng-packagr >20.3.0, the build fails with:

TypeError: Cannot read properties of undefined (reading 'outputCache')

This occurs because ng-packagr v20.3.1 introduced a memory optimization (ng-packagr#3172) that calls dispose() on entry points after they're processed, setting entry.cache = undefined.

Nx's custom writeBundlesTransform was iterating over all entries in the graph, including already-disposed entry points, causing the crash when accessing their cache.

Expected Behavior

Angular library builds should succeed with ng-packagr >20.3.0, including libraries with secondary entry points. Workspaces using lower versions of ng-packagr should remain unaffected.

Solution

Align with ng-packagr's own pattern by using graph.find(isEntryPointInProgress()) to process only the currently in-progress entry point, rather than iterating over all graph entries.

Key changes:

  • Use isEntryPointInProgress() instead of iterating all entries with isEntryPoint()
  • Remove unused BuildGraph import (no longer creating a new graph)
  • Update package node only when processing the primary entry point (more efficient)
  • Return nothing from the transform (original graph passes through, same as ng-packagr)

This approach:

  • Matches ng-packagr's writeBundlesTransform implementation pattern
  • Only accesses cache of the in-progress entry point (guaranteed not to be disposed)
  • Works with all supported ng-packagr versions (v19+) since isEntryPointInProgress() has been available since v19

Related Issue(s)

Fixes #33560

@leosvelperez leosvelperez self-assigned this Dec 10, 2025
@leosvelperez leosvelperez requested a review from a team as a code owner December 10, 2025 15:43
@leosvelperez leosvelperez requested a review from Coly010 December 10, 2025 15:43
@vercel
Copy link

vercel bot commented Dec 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Dec 10, 2025 3:44pm

@netlify
Copy link

netlify bot commented Dec 10, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 65295b7
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6939951b47b7c100089e2a50
😎 Deploy Preview https://deploy-preview-33784--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Dec 10, 2025

View your CI Pipeline Execution ↗ for commit 65295b7

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 21m 31s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2m 24s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 11s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-10 16:10:03 UTC

@leosvelperez leosvelperez merged commit eb6712e into master Dec 10, 2025
15 checks passed
@leosvelperez leosvelperez deleted the issue-33560 branch December 10, 2025 16:13
FrozenPandaz pushed a commit that referenced this pull request Dec 15, 2025
…-lite's write bundles transform function (#33784)

## Current Behavior

When building Angular libraries with `ng-packagr` >20.3.0, the build
fails with:

```bash
TypeError: Cannot read properties of undefined (reading 'outputCache')
```
This occurs because `ng-packagr` v20.3.1 introduced a memory
optimization
([ng-packagr#3172](ng-packagr/ng-packagr#3172))
that calls `dispose()` on entry points after they're processed, setting
`entry.cache = undefined`.

Nx's custom `writeBundlesTransform` was iterating over **all** entries
in the graph, including already-disposed entry points, causing the crash
when accessing their cache.

## Expected Behavior

Angular library builds should succeed with `ng-packagr` >20.3.0,
including libraries with secondary entry points. Workspaces using lower
versions of `ng-packagr` should remain unaffected.

## Solution

Align with `ng-packagr`'s own pattern by using
`graph.find(isEntryPointInProgress())` to process only the currently
in-progress entry point, rather than iterating over all graph entries.

**Key changes:**

- Use `isEntryPointInProgress()` instead of iterating all entries with
`isEntryPoint()`
- Remove unused `BuildGraph` import (no longer creating a new graph)
- Update package node only when processing the primary entry point (more
efficient)
- Return nothing from the transform (original graph passes through, same
as ng-packagr)

This approach:

- Matches `ng-packagr`'s `writeBundlesTransform` implementation pattern
- Only accesses cache of the in-progress entry point (guaranteed not to
be disposed)
- Works with all supported `ng-packagr` versions (v19+) since
`isEntryPointInProgress()` has been available since v19

## Related Issue(s)

Fixes #33560
@github-actions
Copy link
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@nx/angular build fails for ng-packagr >20.3.0

3 participants