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 cache clean --force does not clean cacache files #1785

Closed
jlfwong opened this issue Sep 10, 2020 · 4 comments
Closed

[BUG] npm cache clean --force does not clean cacache files #1785

jlfwong opened this issue Sep 10, 2020 · 4 comments
Labels
Bug thing that needs fixing Release 6.x work is associated with a specific npm 6 release

Comments

@jlfwong
Copy link

jlfwong commented Sep 10, 2020

Hi! I was looking into a bug with very similar behavior as https://npm.community/t/using-npm-ci-does-not-run-prepare-script-for-git-modules/632. It suggested one of the sources of the issue could be a stale cache, so I tried running npm cache clean --force. After digging around the source code, I discovered this does not, in fact, clean caches.

Current Behavior:

Running npm cache clean --force does not remove the files in ~/.npm/index-v5, which appears to be where the files from cacache end up: https://github.com/npm/cacache/blob/1e5d25448f39194f1217047e08613fd726766911/lib/entry-index.js#L249-L251.

As far as I can tell, npm cache clean will delete the ~/.npm/_cacache directory, which doesn't exist for me:

cli/lib/cache.js

Lines 65 to 76 in bd2721d

function clean (args) {
if (!args) args = []
if (args.length) {
return BB.reject(new Error('npm cache clear does not accept arguments'))
}
const cachePath = path.join(npm.cache, '_cacache')
if (!npm.config.get('force')) {
return BB.reject(new Error("As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. On the other hand, if you're debugging an issue with the installer, you can use `npm install --cache /tmp/empty-cache` to use a temporary cache instead of nuking the actual one.\n\nIf you're sure you want to delete the entire cache, rerun this command with --force."))
}
// TODO - remove specific packages or package versions
return rm(cachePath)
}

Expected Behavior:

npm cache clean --force removes all local cache, including those currently contained in ~/.npm/index-v5.

Steps To Reproduce:

Run npm cache clean --force.

~/.npm/index-v5 should be empty or removed, but it isn't.

More importantly, after running npm cache clean --force, no package fetching should be getting cache hits.

More details

I figured this out by digging through a bunch of npm source code. In particular, I added logging to pacote to show that it was hitting the cache even after I ran npm cache clean --force.

Environment:

  • OS: macOS 10.15.3
  • Node: v10.16.3
  • npm: 6.13.4
@jlfwong jlfwong added Bug thing that needs fixing Needs Triage needs review for next steps Release 6.x work is associated with a specific npm 6 release labels Sep 10, 2020
@darcyclarke darcyclarke removed the Needs Triage needs review for next steps label Feb 13, 2021
@k-sai-kiranmayee
Copy link

Hello! Facing the same issue in windows too...

npm version - 5.6.0
OS - Windows 10
Node - v8.9.4

Getting the error - UNKNOWN: unknown error, unlink 'C:\Users\<>\AppData\Roaming\npm-cache\_cacache\index-v5\94\00'

Could you prioritize, please...Unable to install node modules for any of the new projects

If there is any other way to get rid of that error, please help (Have tried npm cache clean/clear --force, Couldn't delete the npm-cache files manually, even tried deleting individually)

Thank you

@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 preproducible 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.

@Tobi-davies
Copy link

I have the same issue, did you get a fix?

@dsbert
Copy link

dsbert commented Oct 12, 2022

Confirmed fixed in npm 8.13.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 6.x work is associated with a specific npm 6 release
Projects
None yet
Development

No branches or pull requests

5 participants