[BUG] npx on Windows: bins with pnpm .cmd shims fail with MODULE_NOT_FOUND since #10044 quotes the executable name

Abierto
#10,344 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@ultimate-kiran ya está trabajando en esto.

Desde el 25/11/2026.

  • #10351 de @ultimate-kiran — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
1-2 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
javascript, node.js
Área
cli, devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
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
  1. On Windows, in a project installed with pnpm: pnpm add -D wrangler (any package with a bin should do).
  2. From PowerShell or cmd, run npx wrangler --version with npm 12.2.3.
  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-shell set)
  • Shims generated by pnpm 11.2.2
Lenguaje dominante
JavaScript
Estrellas
10.3k
Forks
5k
Merge medio
4 d 11 h
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de npm/cli

Todos los issues de npm/cli

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.