npm / npm/cli

[BUG] npm with workspaces fails to install dependencies using dist tags

Open
#8,252 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2
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
Current Behavior

Running npm install in a workspace with package A using preact@latest and package B using preact@experimental only installs preact@latest.

Expected Behavior

Each package should install its own version of the dependency matching the dist tag.

Steps To Reproduce

In a workspaces based environment, for example:

packages.json

{
  "name": "example",
  "version": "1.0.0",
  "license": "UNLICENSED",
  "workspaces": [
    "packages/*"
  ]
}

packages/a/package.json

{
  "name": "a",
  "version": "1.0.0",
  "license": "UNLICENSED",
  "dependencies": {
    "preact": "experimental"
  }
}

packages/b/package.json

{
  "name": "b",
  "version": "1.0.0",
  "license": "UNLICENSED",
  "dependencies": {
    "preact": "latest"
  }
}
  1. Run npm install
  2. Run npm ls --package-lock-only
  3. Observe that it incorrectly dedupes preact to pull only 10.26.5 from latest
├─┬ a@1.0.0 -> ./packages/a
│ └── preact@10.26.5
└─┬ b@1.0.0 -> ./packages/b
  └── preact@10.26.5 deduped
  1. Modify a's dependency to use a version
    packages/a/package.json
{
  "name": "a",
  "version": "1.0.0",
  "license": "UNLICENSED",
  "dependencies": {
    "preact": "11.0.0-experimental.1"
  }
}
  1. Modify b's dependency to use a version
    packages/b/package.json
{
  "name": "a",
  "version": "1.0.0",
  "license": "UNLICENSED",
  "dependencies": {
    "preact": "10.26.5"
  }
}
  1. Run npm install
  2. Run npm ls --package-lock-only
  3. Observe that it now has the correct dependencies for both packages
├─┬ a@1.0.0 -> ./packages/a
│ └── preact@11.0.0-experimental.1
└─┬ b@1.0.0 -> ./packages/a
  └── preact@10.26.5
Environment
  • npm: 10.9.2
  • Node.js: v23.7.0
  • OS Name: MacOS Sequoia 15.3.1
  • System Model Name: Macbook Pro

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

Reproduce the issue from the root packages.json and packages/a/package.json and packages/b/package.json examples by running npm install and npm ls --package-lock-only. Compare the workspace dependency resolution for dist tags with the explicit-version case; done means each workspace retains the version selected for its own dist tag. No source file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.