Skip to content

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

@jlfwong

Description

@jlfwong

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingRelease 6.xwork is associated with a specific npm 6 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions