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

Đang mở
#10,291 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@alphasafal đang làm issue này rồi.

Từ ngày 12/11/2026.

  • #10292 của @alphasafal — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, nodejs
Lĩnh vực
cli, devtools

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
JavaScript
Star
10.3k
Fork
5k
Merge trung bình
4 ngày 11 giờ
Pull request đã merge (30 ngày)
26

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của npm/cli

Tất cả issue của npm/cli

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.