[BUG] install-strategy=linked never reports removed packages: --dry-run shows nothing, --json says removed: 0, and the root `dependencies` script is skipped

オープン
#10,355 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@ultimate-kiran がすでに取り組んでいます。

2026年11月26日 から。

  • #10362 @ultimate-kiran による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript, nodejs
領域
devtools

調査の方向性

Start in workspaces/arborist/lib/arborist/reify.js, at #buildLinkedActualForDiff and #cleanOrphanedStoreEntries, to see why the linked-strategy diff never contains a REMOVE and why cleanup is skipped on dry runs. Reproduce with the steps in the issue, comparing hoisted and linked output for npm uninstall and --json. Done when linked reports the removed count in summary, dry-run and JSON, and the root dependencies script runs on removal.

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

説明

Bug Needs Triage Triage Requested
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

With install-strategy=linked, npm never reports the packages it removes. Compared with the default (hoisted) strategy, using the same project:

Command hoisted linked
npm uninstall e (removes 4 packages) removed 4 packages up to date
npm uninstall e --dry-run removed 4 packages up to date (then the real run removes 4)
npm prune --dry-run lists remove b, remove a up to date (then the real npm prune removes them)
npm uninstall e --json "removed": 4 "removed": 0
root dependencies lifecycle script on uninstall runs does not run

So under linked, a dry run tells you nothing will change and then the real command removes packages, tooling that reads the --json counts sees zeros, and the documented dependencies script ("run after any operations that modify the node_modules directory IF changes occurred") is skipped.

The packages are removed correctly on disk; only the reporting is wrong.

Cause: #buildLinkedActualForDiff in workspaces/arborist/lib/arborist/reify.js builds the actual side of the linked diff only from ideal-tree children, so the diff never contains a REMOVE. #cleanOrphanedStoreEntries deletes the removed packages after the diff, but doesn't report them, and it's skipped entirely on --dry-run. reify-output and the dependencies script both rely on the diff.

Expected Behavior

Removals under install-strategy=linked are reported like under the default strategy: in the summary, in --dry-run (without removing anything), and in --json. The root dependencies script runs when packages are removed.

Steps To Reproduce

Any registry package with a dependency works; for example:

mkdir linked-repro && cd linked-repro && npm init -y
npm install --install-strategy=linked which@4
npm uninstall which --install-strategy=linked --dry-run   # up to date
npm uninstall which --install-strategy=linked --json      # "removed": 0

Compare with --install-strategy=hoisted, which reports removed 2 packages in both cases.

For the lifecycle script, add "scripts": { "dependencies": "node -e \"console.log('dependencies ran')\"" } to package.json and run npm install and then npm uninstall with each strategy (add --foreground-scripts to see the output).

Environment
  • npm: 12.2.3 (latest branch)
  • Node.js: 24.20.0
  • OS Name: Windows 11 (the cause is platform-independent)
主要言語
JavaScript
スター
10.3k
フォーク
5k
平均マージ
4日 11時間
マージ済み PR(30日)
26

環境構築

はじめの一歩

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

npm/cli のほかの issue

npm/cli の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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