[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)
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 88/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, nodejs
調査の方向性
lib/check-bin.js、特に handleReadCmdShimError から始め、npm に同梱されている node_modules/bin-links/node_modules/read-cmd-shim を調査してください。Issue にある Windows のグローバルインストール時の再現手順を実行し、古い shim が EEXIST を発生させることを確認してください。npm に read-cmd-shim 7.0.1 が同梱され、同じ再インストールが --force なしで成功すれば、変更は完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- JavaScript
- スター
- 10.2k
- フォーク
- 4.9k
- 平均マージ
- 5日 4時間
- マージ済み PR(30日)
- 17
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
npm/cli のほかの issue
-
[BUG] npm pkg delete removes the first array item for a nonexistent property対応中かも @drawliin が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 2 日以内に返信
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings logged対応中かも @lazerg が 26 日前に担当しました。 オープンEngineering Priority 1
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
メンテナーはふだん 2 日以内に返信
-
Engineering Priority 2
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
-
`npm audit signatures` does not report how many packages it skipped for want of registry keys対応中かも @greenlincoln05 が 22 日前に担当しました。 オープンPriority 3
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 2 日以内に返信
-
[BUG] E401 error message does not use the configured registry対応中かも @toufiq-dev が 25 日前に担当しました。 オープンBug Priority 3
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
apache/rocketmq-dashboard#7242 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
mihai-vlc/sublime-jsfmt#56 ·
-
Bug v3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
swc-project/swc#12576 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 1 日以内に返信