[BUG] Workspace-scoped `overrides` are ignored for unlinked prerelease workspaces in `npm query` / `loadActual()`

Aperta
#10,356 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@chiliec ci sta già lavorando.

Dal 25/11/2026.

  • #10357 di @chiliec — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, nodejs
Ambito
tooling

Direzione di ricerca

Start in workspaces/arborist/lib/override-set.js: compare getEdgeRule (around line 92) with getNodeRule/getMatchingRule (lines 128-156), where unversioned keys should short-circuit like getEdgeRule does. Reproduce with the workspace layout in the issue, then run Arborist override/workspace tests covering loadActual() and npm query ":invalid". Done means the prerelease workspace ws-a gets the nested [email protected] override and npm query ":invalid" prints []; check linked PR #10357 before starting to avoid duplicate work.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Triage Requested
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 a workspace has not been symlinked into root node_modules yet (for example after installing another workspace with npm install -w ws-b), Arborist#loadActual() loads that workspace target with useRootOverrides: true, which resolves its override set via root.overrides.getNodeRule({ name: pkg.name, version: pkg.version }).

If the root package.json scopes an override under that workspace's bare name (such as "overrides": { "ws-a": { "semver": "7.6.3" } }) and ws-a has a prerelease version ("version": "1.0.0-rc.1"), getNodeRule fails to match the ws-a rule and falls back to the root OverrideSet. As a result, ws-a's dependency edge keeps its raw spec (^6.0.0) instead of the overridden 7.6.3, and npm query ":invalid" falsely reports the hoisted [email protected] as invalid (relevant fields):

[
  {
    "pkgid": "[email protected]",
    "from": [
      "packages/ws-b",
      "packages/ws-a"
    ]
  }
]

With the exact same setup when packages/ws-a/package.json has "version": "1.0.0" (or after a full npm install creates the node_modules/ws-a symlink so overrides propagate via getEdgeRule), ws-a receives the override rule and npm query ":invalid" returns [].

Root cause: in workspaces/arborist/lib/override-set.js, OverrideSet#getNodeRule (and getMatchingRule) checks semver.satisfies(node.version, rule.keySpec) || semver.satisfies(node.version, rule.value) without short-circuiting if (rule.keySpec === '*') return rule the way getEdgeRule does on line 92, and semver.satisfies('1.0.0-rc.1', '*') evaluates to false.

Expected Behavior

Unversioned override keys (rule.keySpec === '*') match prerelease node versions in getNodeRule and getMatchingRule just as they do in getEdgeRule, so [email protected] receives its nested [email protected] override during loadActual() and npm query ":invalid" returns [].

Steps To Reproduce
WORK=$(mktemp -d)
cd "$WORK"
mkdir -p packages/ws-a packages/ws-b

cat > package.json << 'EOF'
{
  "name": "repro",
  "version": "1.0.0",
  "workspaces": ["packages/*"],
  "overrides": {
    "ws-a": {
      "semver": "7.6.3"
    }
  }
}
EOF

cat > packages/ws-a/package.json << 'EOF'
{
  "name": "ws-a",
  "version": "1.0.0-rc.1",
  "dependencies": {
    "semver": "^6.0.0"
  }
}
EOF

cat > packages/ws-b/package.json << 'EOF'
{
  "name": "ws-b",
  "version": "1.0.0",
  "dependencies": {
    "semver": "7.6.3"
  }
}
EOF

npm install -w ws-b --no-audit --no-fund
npm query ":invalid"

Changing "version": "1.0.0-rc.1" in packages/ws-a/package.json to "1.0.0" and re-running npm query ":invalid" prints [].

Environment
  • npm: 12.2.3 (bundles @npmcli/arborist 10.0.5; also reproduces on npm/cli latest at 787f1520fa412e91a5792468f1c7f25b166867a6)
  • Node.js: v24.22.2
  • OS Name: Debian GNU/Linux 12 (bookworm), Linux 6.1 x86_64
  • npm config:
; defaults (empty .npmrc)

Credit: https://ucsbplse.github.io/

Lingua principale
JavaScript
Stelle
10.3k
Fork
5k
Merge medio
4g 11h
PR unite (30g)
26

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di npm/cli

Tutte le issue di npm/cli

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.