Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm creates its cache directory in my $HOME #1451

Closed
WhyNotHugo opened this issue Jun 22, 2020 · 7 comments
Closed

[BUG] npm creates its cache directory in my $HOME #1451

WhyNotHugo opened this issue Jun 22, 2020 · 7 comments
Labels
Bug thing that needs fixing

Comments

@WhyNotHugo
Copy link

What / Why

npm keeps creating its cache directory in my $HOME. I keep very few directories in my $HOME to keep things findable, and its very annoying when apps start littering stuff there.

When

Any time I run things like npm install blah.

Where

$ uname -srmo
Linux 5.7.2-arch1-1 x86_64 GNU/Linux

How

Current Behavior

A directory is creted in $HOME and cache data stored in there.

Steps to Reproduce

  1. Run rm -rf .cache to delete your existing cache.
  2. Navigate to a directory with an existing package.json.
  3. Run npm install.

Expected Behavior

The cache directory should be in $XDG_CACHE_HOME on Linux. Specifically, it should be $XDG_CACHE_HOME/npm. $XDG_CACHE_HOME should default to .cache if undefined.

I believe on macOS there's a different spec for default locations, and things like cache are stored in a different place. I don't know the name of the spec so can't easily link in here.

Who

  • n/a

References

XDG Base Directory Specification

@WhyNotHugo
Copy link
Author

Oh, there's an implementation for nodejs!

@WhyNotHugo
Copy link
Author

Not a duplicate. This bug is about the default behaviour being broken (i.e.: placing cache outside of where all application's cache should be).

#1305 is about the behaviour when overriding the default also being broken.

@astier
Copy link

astier commented Aug 6, 2020

npm is one of the few programs which keeps littering my $HOME. Annoying.

@darcyclarke darcyclarke added the Bug thing that needs fixing label Oct 30, 2020
@lizzielizzielizzie
Copy link

tl;dr: If you are seeing this when running npm ci, you may need to upgrade npm to at least version 6.11.0


I've been digging into this issue (or rather, this issue) for some time now. In my case, a package was downloading an additional binary to the directory specified by process.env.npm_config_cache, and if unset, falling back to ~/.npm. The thing was, I had specified a cache directory. So I did some further digging:

Given the following package.json,

{
  "scripts": {
    "install": "node --eval 'console.log(process.env.node_config_cache)'"
  }
}

Running the following:

  • npm run-script install: variable was set (note: this runs the script as a script, not the lifecycle hook)
  • npm install: variable was set (I wasn't expecting this!)
  • npm ci: variable was not set, even though it was run as part of the lifecycle hooks

That lead me to discover this regression. After upgrading to the latest version of npm I no longer have issues with the cache appearing in unexpected places.

@txtsd
Copy link

txtsd commented May 7, 2021

What's the holdup on this? Should be an easy fix to change and prefer a different directory imo.

@darcyclarke
Copy link
Contributor

npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.

If your bug is reproducible on v7, please re-file this issue using our new issue template.

If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo

Closing: This is an automated message.

@WhyNotHugo
Copy link
Author

Discussion on this issue has now moved here: npm/rfcs#389

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing
Projects
None yet
Development

No branches or pull requests

5 participants