[BUG] npm install materializes registry dependency devDependencies from a pnpm tree

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

维护者通常 2 天内回复

@harshitdeora 已经在做这个了。

开始于 2026年11月7日。

  • #10256 来自 @harshitdeora —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
20/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
领域
backend, cli

调研方向

Start by reading the reproduction steps and the linked pull request #10256, which is already open against this issue. The report identifies a dependency selection problem when npm installs into a pnpm tree, but names no source files or tests to begin from. Done means the fixture no longer materializes the registry dependency’s devDependencies, or npm gives a clear diagnostic, while the npm-managed control still installs both requested packages.

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

描述

cmd:install 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 in an isolated prefix.
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

Adding an unrelated package with npm to a pnpm-installed registry dependency tree materializes that dependency's development-only tools. A one-package starting tree grows by 319 packages, including Mocha and gulp tooling; an npm-managed control for the same root manifest adds only the two requested production packages. This is separate from the TypeError: this fixture exits successfully but builds the wrong dependency set.

Steps To Reproduce

In a new empty directory, using the versions below, run:

printf '{"name":"repro","version":"1.0.0","private":true}
' > package.json
pnpm add --ignore-scripts [email protected]
npm install [email protected] --ignore-scripts --no-audit --no-fund
node -e 'console.log(require("./node_modules/is-number/package.json").devDependencies)'
node -p 'require("./node_modules/mocha/package.json").version'

The starting registry package has no production dependencies. Its development dependencies include benchmarked, chalk, gulp-format-md, and mocha. None is declared in the root manifest. This reproduction does not use a git dependency, local-folder dependency, workspace, build hook, or script execution.

Expected Behavior

Installing a registry dependency for use in a consumer project should not install its test and documentation tools. Install the root manifest's dependencies and their production/peer requirements, or give an actionable diagnostic for an unsupported existing layout.

Actual Behavior

Both tested builds exit 0 with added 319 packages. Mocha is present at node_modules/mocha; the root manifest only declares is-number and picocolors. The dependency's own devDependencies are resolved even though the command does not run from that package's directory.

Evidence

  • Expected source: The devDependencies documentation separates consumer dependencies from the package author's development tools and places development installs at the package root.
  • Failure source: The executed one-package fixture above, npm's added 319 packages output, and the presence of Mocha in the resulting consumer tree.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

Two separate fresh runs with the published CLI and one with current source installed the extra tools. The npm-managed control (npm install [email protected] [email protected] in an empty project) exits 0 with added 2 packages and no Mocha. Adding picocolors using pnpm on the one-package starting tree also exits 0 without installing Mocha. Lifecycle scripts remained disabled throughout, so the observation is dependency materialization rather than a build-script effect. Other tested pnpm trees failed with E404 when development-only package references were unavailable; that is additional impact of this dependency-selection behavior, not a claim that all pnpm trees fail.

Environment
  • Platform: Linux x86_64.
  • Node.js: 26.13.0.
  • Latest published npm: 12.2.2, installed in an isolated prefix.
  • Current latest source: ab930df82a63796a9390b9766f11e5c4c0fc9e1c, bootstrapped using node scripts/resetdeps.js; the same result was observed with node . install.
  • pnpm: 12.18.0, installed in an isolated prefix.
  • User configuration, cache, and store were isolated; lifecycle scripts and audit were disabled for the reduced tests.

Restoration check

Run the one-package fixture in a fresh directory and verify that the npm command either installs only the intended production/peer graph without Mocha or reports the unsupported existing layout clearly. The clean npm-managed control must still install both requested packages. No dependency's test tooling should be materialized simply because it resides in pnpm's store.

References

  • Existing non-npm-tree tracking issue: related interoperability scope; its reported null-target crash and discussion do not describe successful installation of dependency development tools.
  • Merged npm-store fix: addressed development edges for npm's own .store layout; the current .pnpm fixture still installs the tools. A shared cause is not asserted.
  • Closed git-dependency report: maintainers explained that git dependencies with build scripts can intentionally install development tools. This fixture uses a registry package and disables lifecycle scripts, so it does not rely on that declined behavior change.

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: The observed fixture downloads and installs hundreds of unnecessary packages; other tested fixtures cannot complete when a dependency's development-only package reference is unavailable. The behavior is bounded to existing pnpm trees in this investigation.
  • Workaround status: available
  • Workaround basis: Continuing with pnpm leaves Mocha absent. Recreating the dependency tree using npm installs only the two intended production packages in the tested clean control.
主要语言
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 摘要。