Clear *just one* package from NPM cache

11.4k Views Asked by At

The problem:

sometimes I run

npm install x@latest

but it doesn't actually pull the latest version of the package (that is lame).

However, if I do:

npm cache clean --force && npm install x@latest

it will pull the latest

but I actually would rather avoid deleting the whole cache and just delete the cache for a single package, e.g.:

npm cache clean x --force

but that doesn't seem to be allowed. Anyone know a good workaround?

perhaps simply:

rm -rf $HOME/.npm/x

?

3

There are 3 best solutions below

1
On
> npm cache ls [email protected]
make-fetch-happen:request-cache:https://registry.npmjs.org/vue/-/vue-2.6.12.tgz
make-fetch-happen:request-cache:https://registry.npmjs.org/vue
make-fetch-happen:request-cache:https://registry.npmjs.org/vue

all list item is the cache key, then clean the cache by key

> npm cache clean make-fetch-happen:request-cache:https://registry.npmjs.org/vue/-/vue-2.6.12.tgz

> npm cache clean make-fetch-happen:request-cache:https://registry.npmjs.org/vue

> npm cache clean make-fetch-happen:request-cache:https://registry.npmjs.org/vue

or use shell to batch handle

npm cache ls [email protected] | xargs npm cache clean
1
On

npm cache clean --force cache clean command will look for the package.json https://sebhastian.com/npm-clear-cache/

0
On

I faced that issue, my current workaround is to upgrade the package again. as the sha is changed during installation, it will automatically pull the package and update the cache, I tested with yarn and it works, haven't tested with npm but I assume it will work as expected.

for npm:

npm update x@latest

for yarn

yarn upgrade-interactive --latest