Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#10,140 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
88/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, nodejs
Área
cli, devtools

Línea de trabajo

Empieza por lib/check-bin.js, especialmente handleReadCmdShimError, e inspecciona el node_modules/bin-links/node_modules/read-cmd-shim incluido con npm. Ejecuta la reproducción de la instalación global en Windows del issue para confirmar que el shim obsoleto provoca EEXIST. El cambio estará completo cuando npm incluya read-cmd-shim 7.0.1 y la misma reinstalación funcione sin --force.

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

Descripción

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-shim 9.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-shim 7.0.0 matches sh shims with
    /"[$]basedir[/]([^"]+?)"\s+"[$]@"/, so it rejects every shim that cmd-shim 9 writes with ENOTASHIM.

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:

  1. npm install -g --prefix <prefix> [email protected]. This writes <prefix>\prettier, prettier.cmd and prettier.ps1; the sh shim uses $basedir_win.
  2. Delete <prefix>\node_modules\prettier and keep the three shims (what an interrupted install leaves behind).
  3. 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 --force in 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-12 bundles 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
Lenguaje dominante
JavaScript
Estrellas
10.2k
Forks
4.9k
Merge medio
5 d 4 h
PR fusionados (30 d)
17

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.