[BUG] EACCES on ~/.npmrc is reported as a root-owned cache folder

Abierto
#10,272 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@ump45nose ya está trabajando en esto.

Desde el 10/11/2026.

  • #10273 de @ump45nose — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
javascript, node.js
Área
cli

Línea de trabajo

The issue points to lib/utils/error-message.js, where the cache path check is described. Read that check and reproduce the failure with the provided read-only ~/.npmrc steps. Done when the error for ~/.npmrc names the file and shows the generic permission message, while paths inside the cache still receive the cache-specific message.

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

Descripción

Bug Priority 3
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

When npm cannot write ~/.npmrc, it reports that the cache folder contains root-owned files and tells the user to run sudo chown -R on ~/.npm. The cache is fine, so the suggested command does not fix anything. The real problem is that ~/.npmrc is not writable. That happens, for example, when a dotfiles manager such as Nix Home Manager links it to a read-only file.

npm login on such a machine fails like this:

npm error code EACCES
npm error syscall open
npm error path /Users/<user>/.npmrc
npm error errno -13
npm error
npm error Your cache folder contains root-owned files, due to a bug in previous versions of npm which has since been addressed.
npm error
npm error To permanently fix this problem, please run:
npm error   sudo chown -R 501:20 "/Users/<user>/.npm"

Suspected cause: lib/utils/error-message.js decides that an error is inside the cache with a plain string prefix check, er.path.startsWith(npm.config.get('cache')). With the default cache ~/.npm, the path ~/.npmrc passes that check because the string ~/.npmrc starts with ~/.npm. Any sibling path that starts with the cache path, such as ~/.npm-global, would match the same way.

Expected Behavior

npm should show the root-owned cache message only for paths inside the cache directory. For ~/.npmrc, it should show the generic permission error, which names the file that could not be written.

Steps To Reproduce
export HOME="$(mktemp -d)"
printf 'fund=true\n' > "$HOME/.npmrc"
chmod 444 "$HOME/.npmrc"
npx -y [email protected] config set fund=false

npm prints path <tmp>/.npmrc followed by the root-owned cache message and a sudo chown -R command for <tmp>/.npm. npm login hits the same message, because it also saves to the user config.

Environment
  • npm: 12.2.2 (also seen on 11.19.1)
  • Node.js: 24.22.2 (also seen on 26.13.0)
  • OS Name: macOS 27.0
  • System Model Name: Apple Silicon Mac
  • npm config: default, apart from a read-only ~/.npmrc

🤖 Created with Claude Opus 5.5 in T3 Code

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.