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

未关闭
#10,291 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@alphasafal 已经在做这个了。

开始于 2026年11月12日。

  • #10292 来自 @alphasafal —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
javascript, nodejs
领域
cli, devtools

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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
主要语言
JavaScript
星标
10.3k
派生
5k
平均合并
4 天 11 小时
30 天内合并 PR
26

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

npm/cli 的其他 Issue

查看 npm/cli 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。