[BUG] "dependencies" as an array or string makes npm install packages named "0", "1", ...

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

I maintainer di solito rispondono entro 2 giorni

@alphasafal ci sta già lavorando.

Dal 12/11/2026.

  • #10292 di @alphasafal — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
javascript, nodejs
Ambito
cli, devtools

Direzione di ricerca

The bug is in how Arborist reads the dependencies, optionalDependencies, devDependencies and peerDependencies fields of package.json with Object.entries, so array indexes and string characters become package names. Start by reproducing with the two commands in the issue, using a dependencies array with is-number, then with ["latest","*"]. Done means invalid non-object fields are ignored with a warning pointing to npm pkg fix, or fail with a clear error. A linked pull request (#10292) already exists, so check it before starting.

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

Descrizione

area:package-json Bug Priority 3
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

If dependencies (or optionalDependencies, devDependencies, peerDependencies) in package.json is an array or a string, Arborist reads it with Object.entries, so each index becomes a package name.

"dependencies": ["is-number"] fails with No matching version found for 0@is-number, which doesn't point at the real problem.
With entries like "latest" or "*", npm installs the unrelated public packages named 0 and 1 (and their dependencies), which exist on the registry under other owners.
npm pkg fix already knows how to convert these fields, but install never suggests it.

Expected Behavior

npm should not treat array indexes or string characters as package names.
It should ignore the invalid field with a clear warning that suggests npm pkg fix, or fail with a clear error.

Steps To Reproduce
mkdir deps-array && cd deps-array
echo '{"name":"app","version":"1.0.0","dependencies":["is-number"]}' > package.json
npm install
# npm error notarget No matching version found for 0@is-number.

echo '{"name":"app","version":"1.0.0","dependencies":["latest","*"]}' > package.json
npm install
ls node_modules
# 0  1  ... (the packages named "0" and "1" from the registry, plus their dependencies)
Environment
  • npm: 12.2.2 (also on the latest branch at 8f92e74)
  • Node.js: 22.23.4
  • OS Name: Linux
  • npm config: defaults
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.