[BUG] npx on Windows: bins with pnpm .cmd shims fail with MODULE_NOT_FOUND since #10044 quotes the executable name
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js
Direzione di ricerca
The cause is in libnpmexec/lib/run-script.js, where #10044 began quoting the executable name for cmd.exe. Reproduce on Windows by running npx against a bin whose shim uses %~dp0 directly, and compare the quoted and unquoted forms. A fix already has an open pull request (#10351), so review or test that work rather than starting a parallel change.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
Current Behavior
On Windows, npx <bin> fails with MODULE_NOT_FOUND when the bin's .cmd shim in node_modules\.bin was written by pnpm. The shim looks for the package one folder too high:
PS C:\project\pkg> npx wrangler --version
npm notice run ^"wrangler^" --version
Error: Cannot find module 'C:\project\wrangler\bin\wrangler.js'
code: 'MODULE_NOT_FOUND'
The file is really at C:\project\pkg\node_modules\wrangler\bin\wrangler.js. This worked before the upgrade to npm 12.
Cause, as far as I can tell: #10044 made libnpmexec/lib/run-script.js quote the executable name for cmd.exe, so the script becomes "wrangler" --version. When cmd.exe starts a batch file by a quoted bare name found through PATH, and arguments follow, %~dp0 inside that batch file resolves to the current directory instead of the batch file's own folder. pnpm's shim runs node "%~dp0\..\wrangler\bin\wrangler.js", so it points at C:\project\pkg\..\wrangler\....
npm's own cmd-shim output is not affected because it reads %~dp0 through CALL :find_dp0. Shims written by other tools (pnpm, and anything else that uses %~dp0 directly) break.
The same quirk without npm, run from PowerShell 7 in C:\tmp\dp0, with C:\tmp\dp0\bin\showdir.cmd containing @echo %~dp0 and C:\tmp\dp0\bin on PATH:
cmd /d /s /c 'showdir a b' -> C:\tmp\dp0\bin\ (correct)
cmd /d /s /c '"showdir" a b' -> C:\tmp\dp0\ (current directory)
Expected Behavior
npx wrangler --version runs the bin from node_modules\.bin, as it did before npm 12.
Possible fixes: only quote the name when it contains cmd metacharacters, or resolve the bin to its absolute path before quoting it.
Steps To Reproduce
- On Windows, in a project installed with pnpm:
pnpm add -D wrangler(any package with abinshould do). - From PowerShell or cmd, run
npx wrangler --versionwith npm 12.2.3. - See
Cannot find module '<parent of project>\wrangler\bin\wrangler.js'.
pnpm exec wrangler --version works in the same folder. Workaround: setting npm_config_script_shell=pwsh makes npx use the .ps1 shim, which resolves its folder correctly.
Environment
- npm: 12.2.3
- Node.js: 24.15.0
- OS Name: Windows 11 Pro (10.0.26200)
- System Model Name: x64 desktop
- npm config: defaults (no
script-shellset) - Shims generated by pnpm 11.2.2
- Lingua principale
- JavaScript
- Stelle
- 10.3k
- Fork
- 5k
- Merge medio
- 4g 11h
- PR unite (30g)
- 26
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di npm/cli
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 2 giorni
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endingsForse già presa @saruk-vedant l’ha presa 7 giorni fa. ApertaBug Needs Triage Triage Requested
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 2 giorni
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyForse già presa @drawliin l’ha presa 42 giorni fa. Apertacmd:delete Priority 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 2 giorni
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. ApertaEngineering Priority 1
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
I maintainer di solito rispondono entro 2 giorni
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysForse già presa @greenlincoln05 l’ha presa 63 giorni fa. ApertaPriority 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 2 giorni
Issue simili
-
docs: add SECURITY.md vulnerability reporting policyForse già presa @AK-Lmn l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
flisk-sh/linux2wasm#12 ·
I maintainer di solito rispondono entro 1 giorno
-
possible bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Mintplex-Labs/anything-llm#7388 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 60/100
I maintainer di solito rispondono entro 1 giorno
-
v6: Minified bootstrap.min.css is missing header infoForse già presa @lazerg l’ha presa oggi. Apertabug build confirmed has-pr v6
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
githubnext/gh-aw-workshop#6332 ·
I maintainer di solito rispondono entro 1 giorno