Skip to content

fix(@angular/cli): support npm 12 metadata array and error formats - #33680

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix-npm-12-metadata
Jul 30, 2026
Merged

fix(@angular/cli): support npm 12 metadata array and error formats#33680
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix-npm-12-metadata

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

In npm 12, npm view --json <packageName> <fields> returns package metadata formatted as an array of objects rather than a single JSON object. This caused metadata.versions to evaluate to undefined and throw Cannot read properties of undefined (reading 'filter') during ng update.

Additionally, npm 12 wraps JSON error output inside an error property ({ "error": { "code": ... } }), which was not unwrapped by parseNpmLikeError.

Issue Number: Closes #33679

What is the new behavior?

  • parseNpmLikeMetadata now checks if JSON.parse(stdout) is an array and returns the first valid PackageMetadata object from the array.
  • parseNpmLikeError now unwraps error objects when error JSON is wrapped in an array or an "error" property ({ "error": { ... } }).
  • Added unit tests to parsers_spec.ts covering npm 12+ metadata array output and error format unwrapping.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the package manager parsers to support npm 12+ output formats, specifically handling metadata and errors wrapped in arrays or nested under an error property. The review feedback points out that while parseNpmLikeError was updated to handle array-wrapped errors, the corresponding unit tests only cover the error property wrapping. It is recommended to add unit tests to cover both array-wrapped errors and errors wrapped in both an array and an error property to ensure full test coverage.

Comment thread packages/angular/cli/src/package-managers/parsers_spec.ts
@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label Jul 30, 2026
In npm 12, `npm view --json <packageName> <fields>` returns package metadata formatted as an array of objects rather than a single JSON object. This caused `metadata.versions` to evaluate to `undefined` and throw `Cannot read properties of undefined (reading 'filter')` during `ng update`.

Additionally, npm 12 wraps JSON error output inside an `error` property (`{ "error": { "code": ... } }`), which is now unwrapped by `parseNpmLikeError`.

Closes angular#33679
@alan-agius4
alan-agius4 force-pushed the fix-npm-12-metadata branch from 951a7c1 to 6050d0d Compare July 30, 2026 07:17
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jul 30, 2026
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 30, 2026
@alan-agius4
alan-agius4 merged commit e148a8d into angular:main Jul 30, 2026
41 checks passed
@alan-agius4
alan-agius4 deleted the fix-npm-12-metadata branch July 30, 2026 07:46
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

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

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/cli target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

incompatibility btween angular/cli@22.1 and npm@12

2 participants