Skip to content

fix(@angular/cli): handle npm-aliased and unfetchable packages in ng update#32943

Open
maruthang wants to merge 1 commit intoangular:mainfrom
maruthang:fix-28834-npm-alias-update
Open

fix(@angular/cli): handle npm-aliased and unfetchable packages in ng update#32943
maruthang wants to merge 1 commit intoangular:mainfrom
maruthang:fix-28834-npm-alias-update

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

@maruthang maruthang commented Apr 6, 2026

Summary

  • ng update would fail with a 404 error when package.json contains dependencies using npm aliases ("my-pkg": "npm:real-package@^1.0.0") or packages from private/non-npmjs registries
  • The Promise.all() for fetching package metadata would reject entirely when any single package couldn't be fetched, even if it wasn't part of the update
  • The fix filters out npm: aliased packages early (since the alias name differs from the real package name) and catches individual fetch errors gracefully, allowing the existing reduce logic to handle missing packages

Closes #28834

Test plan

  • Run ng update on a project with npm: aliased dependencies — should complete without error
  • Run ng update on a project with private registry packages — should skip unfetchable packages gracefully
  • Run ng update @angular/core on a normal project — should work as before

…update

When `ng update` encounters packages using npm aliases (`npm:` protocol)
or packages that cannot be fetched from the registry (private registries,
JSR, AWS CodeArtifact), the entire update process would fail with a 404
error because `Promise.all()` rejects on any single fetch failure.

The fix:
1. Filters out `npm:` aliased packages early in `isPkgFromRegistry()` since
   the dependency key name differs from the actual package name
2. Catches individual fetch errors in the parallel metadata fetch, returning
   a partial result that the existing reduce logic already handles gracefully

Closes angular#28834
Copy link
Copy Markdown

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

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 enhances the Angular CLI update schematic to better handle npm aliases and metadata fetch failures by returning partial results on error. The review feedback recommends a more robust implementation for alias detection using the npa.resolve result type rather than a simple string prefix check.

Comment on lines +807 to 816
// npm: aliases (e.g., "npm:real-package@^1.0.0") resolve as registry packages
// but the dependency key name differs from the actual package name, so registry
// lookups using the alias name would fail with a 404.
if (specifier.startsWith('npm:')) {
return false;
}

const result = npa.resolve(name, specifier);

return !!result.registry;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using the result of npa.resolve to detect aliases is more robust than a manual string prefix check. This approach handles edge cases like case-insensitivity (e.g., NPM:) and potential whitespace consistently with how the rest of the package resolution logic operates.

Suggested change
// npm: aliases (e.g., "npm:real-package@^1.0.0") resolve as registry packages
// but the dependency key name differs from the actual package name, so registry
// lookups using the alias name would fail with a 404.
if (specifier.startsWith('npm:')) {
return false;
}
const result = npa.resolve(name, specifier);
return !!result.registry;
// npm: aliases (e.g., "npm:real-package@^1.0.0") resolve as registry packages
// but the dependency key name differs from the actual package name, so registry
// lookups using the alias name would fail with a 404.
const result = npa.resolve(name, specifier);
return !!result.registry && result.type !== 'alias';

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng update breaks on "private" packages

1 participant