31

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

?

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • You cannot delete only one package. If you look at the docs, they said the following: "There is currently no method exposed through npm to inspect or directly manage the contents of this cache. In order to access it, cacache must be used directly." – Jonathan Brizio Apr 10 '19 at 18:18
  • [Here's something that might let you remove cache entries](https://www.npmjs.com/package/npm-cache-rm) – gman Sep 22 '20 at 16:23

3 Answers3

8
> npm cache ls vue@2.6.12
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 vue@2.6.12 | xargs npm cache clean
Liuer Hei
  • 89
  • 1
  • 5
  • 2
    `npm cache ls` is not working with older npm versions (6 and 7, based on the doc. I checked with npm 6.14.16) – Jidehem Jan 18 '23 at 13:13
1

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

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 09 '22 at 18:44
0

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
sina.ce
  • 460
  • 2
  • 8