Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[BUG] npm pkg delete removes the first array item for a nonexistent property

Aperta Adatta ai principianti
#10,141 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@drawliin ci sta già lavorando.

Dal 19/10/2026.

  • #10142 di @drawliin — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
83/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js
Ambito
cli

Direzione di ricerca

L’issue rimanda a lib/utils/queryable.js, in particolare al percorso di eliminazione alle righe 197–204. Leggi quel codice e segui come Queryable.delete() gestisce una chiave stringa quando il suo elemento genitore è un array; confrontalo con il comportamento segnalato di keywords[1]. Il lavoro è completato quando l’eliminazione di una proprietà dell’array inesistente lascia l’array invariato o rifiuta il percorso senza salvare, mentre l’eliminazione di un indice valido continua a funzionare.

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

Descrizione

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

npm pkg delete keywords.missing removes the first keyword.. even though there is no missing property. the command exits 0 without a warning.

with "keywords": ["alpha", "beta"], the result is "keywords": ["beta"].

keywords.beta does the same thing.. it removes "alpha", not the value named "beta". contributors.missing also removes the first contributor when contributors is an array of objects.

expected behavior

a nonexistent property should not cause an unrelated array item to be deleted.. either leave the array unchanged or reject the path without saving changes.

steps to reproduce
mkdir npm-pkg-delete-repro
cd npm-pkg-delete-repro

echo '{"name":"pkg-delete-repro","version":"1.0.0","keywords":["alpha","beta"]}' > package.json

npm pkg delete keywords.missing
cat package.json

result:

{
  "name": "pkg-delete-repro",
  "version": "1.0.0",
  "keywords": [
    "beta"
  ]
}

resetting the fixture and running npm pkg delete 'keywords[1]' correctly removes "beta". deleting a missing property from an object.. such as scripts.missing.. leaves its existing properties alone.

in lib/utils/queryable.js, the delete path calls _data.splice(_key, 1) whenever the parent is an array. a nonnumeric key remains a string.. splice() coerces it to NaN and treats that as index 0.

environment
  • npm: 12.2.0, the current latest registry tag
  • Node.js: v24.21.0
  • macOS 26.4, arm64
  • reproduced with empty user and global npm config files

also reproduced with npm 11.19.0. the current latest branch's Queryable.delete() reproduces it directly too.. checked at ae98c62586b6fea44114f72e249e246a2981de70.

Lingua principale
JavaScript
Stelle
10.2k
Fork
4.9k
Merge medio
5g 4h
PR unite (30g)
17

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.