Skip to content

[BUG] NPM crashes when no access to cache directory, but has access to registry. #6245

Closed
@lluio

Description

@lluio

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

This previous issue (#4996, fixed by #5197) is still relevant. If the npm cache directory is invalid (e.g. /dummy), but npm does not have access to the registry (behind proxy, or npm_config_offline=true), the ENOENT error is logged, but the app does not crash. If npm does have access to registry, it logs the error and then crashes.

I am, additionally, curious why npm is connecting to the registry at all just because the default cache dir is restricted. I.e:

  • With a valid directory, no http-request is logged with NODE_DEBUG=http
  • With an illegal directory (e.g. /dummy) the node debug logs show that a GET request is being sent to registry.npmjs.org

Expected Behavior

NPM should not crash with an invalid cache-location just because it has access to the registry. This should, like in #5197, be logged silently as an error and not cause the program to crash.

Steps To Reproduce

  1. Using [email protected] and [email protected]
  2. Run a basic npm script, such as this:
{
  "scripts": {
    "dummy": "echo 'hello' && sleep 2 && echo 'Yeet!'"
  }
}
  1. With access to registry.npmjs.org, run this command:
npm_config_cache=/123 npm run dummy --loglevel=silly
  1. This error is logged:
npm verb cli /home/.../.nvm/versions/node/v18.15.0/bin/node /home/.../.nvm/versions/node/v18.15.0/bin/npm
npm info using [email protected]
npm info using [email protected]
npm verb cache could not create cache: Error: EACCES: permission denied, mkdir '/123'
npm verb logfile could not create logs-dir: Error: EACCES: permission denied, mkdir '/123'
npm verb title npm run dummy
npm verb argv "run" "dummy" "--loglevel" "silly"
npm verb logfile logs-max:10 dir:/123/_logs/2023-03-13T12_57_20_721Z-
npm verb logfile could not be created: Error: ENOENT: no such file or directory, open '/123/_logs/2023-03-13T12_57_20_721Z-debug-0.log'
npm verb logfile no logfile created
npm sill logfile done cleaning log files

> dummy
> echo 'hello' && sleep 2 && echo 'Yeet!'

hello
npm verb stack Error: EACCES: permission denied, mkdir '/123'
npm verb cwd /home/.../temp
npm verb Linux 5.19.0-35-generic
npm verb node v18.15.0
npm verb npm  v9.6.1
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /123
npm ERR! errno -13
npm verb Error: EACCES: permission denied, mkdir '/123' 
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 1000:1000 "/123"
npm verb exit -13
npm verb unfinished npm timer command:run 1678712240740
npm verb code -13

npm ERR! Log files were not written due to an error writing to the directory: /123/_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
  1. Just to demonstrate, now run with npm_config_offline=true, and it runs with the following output:
npm verb cli /home/.../.nvm/versions/node/v18.15.0/bin/node /home/.../.nvm/versions/node/v18.15.0/bin/npm
npm info using [email protected]
npm info using [email protected]
npm verb cache could not create cache: Error: EACCES: permission denied, mkdir '/123'
npm verb logfile could not create logs-dir: Error: EACCES: permission denied, mkdir '/123'
npm verb title npm run dummy
npm verb argv "run" "dummy" "--loglevel" "silly"
npm verb logfile logs-max:10 dir:/123/_logs/2023-03-13T12_58_32_261Z-
npm verb logfile could not be created: Error: ENOENT: no such file or directory, open '/123/_logs/2023-03-13T12_58_32_261Z-debug-0.log'
npm verb logfile no logfile created
npm sill logfile done cleaning log files

> dummy
> echo 'hello' && sleep 2 && echo 'Yeet!'

hello
Yeet!
npm verb exit 0
npm info ok 

Environment

  • npm: 9.6.1
  • Node.js: 18.15.0
  • OS Name: Ubuntu Linux
  • npm_config_cache set to unpermitted directory, such as /dummy.

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 9.xwork is associated with a specific npm 9 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions