Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#10,141 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@drawliin がすでに取り組んでいます。

2026年10月19日 から。

  • #10142 @drawliin による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
83/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js
領域
cli

調査の方向性

issue では lib/utils/queryable.js、特に197–204行目の削除処理が示されています。そのコードを読み、親が配列の場合に Queryable.delete() が文字列キーをどのように処理するかを追い、報告された keywords[1] の挙動と比較してください。存在しない配列プロパティを削除しても配列が変更されないか、保存せずにパスを拒否し、有効なインデックスの削除は引き続き機能すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
JavaScript
スター
10.2k
フォーク
4.9k
平均マージ
5日 4時間
マージ済み PR(30日)
17

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

npm/cli のほかの issue

npm/cli の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。