[BUG] Windows: EEXIST on bin shims that npm wrote itself (bundled read-cmd-shim 7.0.0 cannot read the $basedir_win shims of cmd-shim 9.0.2)
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, nodejs
Hướng nghiên cứu
Bắt đầu với lib/check-bin.js, đặc biệt là handleReadCmdShimError, và kiểm tra node_modules/bin-links/node_modules/read-cmd-shim được npm đóng gói. Chạy quy trình tái hiện cài đặt toàn cục trên Windows của issue để xác nhận rằng shim cũ kích hoạt EEXIST. Thay đổi hoàn tất khi npm đóng gói read-cmd-shim 7.0.1 và thao tác cài đặt lại tương tự thành công mà không cần --force.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
On Windows, npm 12.2.0 does not recognise the sh shims that it writes itself. When an install has to inspect an existing shim, the bin check fails with EEXIST, although the shim points into the very package being installed:
npm error code EEXIST
npm error path <prefix>\prettier
npm error EEXIST: file already exists
npm error File exists: <prefix>\prettier
npm error Remove the existing file and try again, or run npm
npm error with --force to overwrite files recklessly.
Cause: the bin-links bundled in npm 12.2.0 carries two nested dependencies that disagree.
node_modules/bin-links/node_modules/cmd-shim9.0.2 writes the exec line of the sh shim as
exec "$PROG_EXE" "$basedir_win/node_modules/prettier/bin/prettier.cjs" "$@".node_modules/bin-links/node_modules/read-cmd-shim7.0.0 matches sh shims with
/"[$]basedir[/]([^"]+?)"\s+"[$]@"/, so it rejects every shim that cmd-shim 9 writes withENOTASHIM.
lib/check-bin.js turns any read error other than ENOENT into EEXIST (handleReadCmdShimError), so npm treats its own shim as a foreign file.
A normal update is not affected: arborist moves the installed version and its bin paths aside ([_retireShallowNodes]) before [_reifyNode] calls [_checkBins]. The error appears when an existing shim is not moved aside first. The case that hit me: a global install was interrupted, the package folder was gone but its shims remained, and the reinstall failed. The only way out npm offers is --force.
read-cmd-shim 7.0.1 (npm/read-cmd-shim#137, merged 2026-09-23) already accepts "$basedir(?:_win)?/", but npm 12.2.0 still bundles 7.0.0, and so does the 12.2.1 tarball (next-12).
Expected Behavior
npm recognises its own shims and reinstalls the package, as it does for shims in the old "$basedir/" form.
Steps To Reproduce
Fresh prefix, empty user config (npm_config_userconfig pointing to an empty file), npm 12.2.0, Node 24.20.0:
npm install -g --prefix <prefix> [email protected]. This writes<prefix>\prettier,prettier.cmdandprettier.ps1; the sh shim uses$basedir_win.- Delete
<prefix>\node_modules\prettierand keep the three shims (what an interrupted install leaves behind). npm install -g --prefix <prefix> [email protected]fails with the EEXIST error above.
Controls, each in its own fresh prefix:
- The same steps, but rewrite the exec line of the sh shim to the old
"$basedir/node_modules/..."form before step 3: the install succeeds. - The same steps with
--forcein step 3: the install succeeds. - A normal update with the shims in place (
[email protected], then[email protected]): succeeds.
Direct check on the shim from step 1:
require('<npm>/node_modules/bin-links/node_modules/read-cmd-shim')('<prefix>/prettier')
// read-cmd-shim 7.0.0 (bundled in npm 12.2.0 and 12.2.1): rejects with ENOTASHIM
// read-cmd-shim 7.0.1: resolves to 'node_modules/prettier/bin/prettier.cjs'
Suggested fix: bundle read-cmd-shim 7.0.1. bin-links 7.0.0 already allows it ("read-cmd-shim": "^7.0.0").
Environment
- npm: 12.2.0 (the 12.2.1 tarball on
next-12bundles the same read-cmd-shim 7.0.0) - Node.js: 24.20.0
- OS Name: Windows 11 Home 10.0.26300
- System Model Name: not hardware-specific
- npm config:
; "env" config from environment
cache = "<sandbox>\\cache"
userconfig = "<sandbox>\\empty.npmrc"
; "cli" config from command line options
prefix = "<sandbox>\\prefix"
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v24.20.0
; npm version = 12.2.0
- Ngôn ngữ chính
- JavaScript
- Star
- 10.2k
- Fork
- 4.9k
- Merge trung bình
- 5 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 17
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của npm/cli
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyCó thể đã có người làm @drawliin đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 2 ngày
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedCó thể đã có người làm @lazerg đã nhận 26 ngày trước. Đang mởEngineering Priority 1
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Engineering Priority 2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 2 ngày
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysCó thể đã có người làm @greenlincoln05 đã nhận 23 ngày trước. Đang mởPriority 3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] E401 error message does not use the configured registryCó thể đã có người làm @toufiq-dev đã nhận 26 ngày trước. Đang mởBug Priority 3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 2 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
fix(套件): test_bundle 往仓库的 preset/skills 写哨兵,并发跑的 test_installer 拷贝时撞 ENOENT(CI 红)Có thể đã có người làm @Miaotofu01 đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Miaotofu01/Study-Mate#216 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
-
beginner-friendly category:fixtures community enhancement first-timers-only good first issue hacktoberfest help wanted low hanging fruit micro-contribution type: task up-for-grabs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Berserk-hub150/skillhawk#229 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 8 ngày