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

Đang mở
#10,355 1 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

@ultimate-kiran đang làm issue này rồi.

Từ ngày 26/11/2026.

  • #10362 của @ultimate-kiran — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, nodejs
Lĩnh vực
devtools

Hướng nghiên cứu

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.

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

Mô tả

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)
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.