npm / npm/cli

[BUG] Changing `packageExtensions` or `.npm-extension` upgrades locked packages to the newest version in range

Open
#9,981 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
This is not just a request to bump a dependency for a CVE
  • This is not solely a request to bump a dependency for a CVE
Current Behavior

When the packageExtensions or .npm-extension hash changes, npm re-resolves every extended package from its dependency spec and installs the newest version in range instead of the locked one. This also hits packages whose selector did not change. A manifest-only repair therefore changes installed code (seen in a large monorepo: @tanstack/react-router 1.133.36 to 1.170.36, vite 8.2.2 to 8.3.0).

Expected Behavior

Locked versions that still satisfy their edges are kept; only the extended manifest is refetched.

Steps To Reproduce
mkdir x && cd x
P='"peerDependencies":{"x":"*"},"peerDependenciesMeta":{"x":{"optional":true}}'
echo "{\"dependencies\":{\"abbrev\":\"3.0.0\",\"ms\":\"2.1.2\"},\"packageExtensions\":{\"abbrev\":{$P}}}" > package.json
npm install
echo "{\"dependencies\":{\"abbrev\":\"^3.0.0\",\"ms\":\"^2.1.2\"},\"packageExtensions\":{\"abbrev\":{$P}}}" > package.json
npm install   # up to date
npm ls        # abbrev@3.0.0, ms@2.1.2
echo "{\"dependencies\":{\"abbrev\":\"^3.0.0\",\"ms\":\"^2.1.2\"},\"packageExtensions\":{\"abbrev\":{$P},\"ms\":{$P}}}" > package.json
npm install   # changed 2 packages
npm ls        # expected abbrev@3.0.0, ms@2.1.2; actual abbrev@3.0.1, ms@2.1.3

Same result with .npm-extension.mjs and with install-strategy=linked.

Environment
  • npm: 12.0.2 (release and latest c9876d7ea)
  • Node.js: v24.18.0
  • OS: macOS Darwin 25.6.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal package.json reproduction with npm install and npm ls, then trace the npm CLI install path that handles packageExtensions and lockfile reuse. Done means changing packageExtensions or .npm-extension refetches the extended manifest without upgrading locked packages that still satisfy their ranges, including with install-strategy=linked.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.