Home Articles

Stop bulldozing your npm cache clean.

Oct 31, 2023 ∘ Yoko Ishioka
Snowplow pushing packages

As of version 5, npm (already one of the best packaging managers) became 'virtually self-healing'. This means you should no longer have to face those terrifying moments of desperation when you say what the fuck to the CLI that is emphatically assuring you there is no reason to force a cache clean because everything is in perfect order and the bug must undoubtedly be something on your end.

But if the versions are all lined up, the dependencies have been dealt with, vulnerabilities squashed, and you're still running into errors, there might be only one thing left...

  npm cache clean --force

What is wrong with forcing a cache clean?

BUT WAIT! There's a reason why the CLI says this is a very futile and foolish thing to even try. It's the same as running the uninstall and starting all over again. If there's any problem in your configuration, you won't have any backups to get you through.

Verify the cache instead

Now, there's a safer alternative to try first:

npm cache verify

This command tells npm to figure out what it needs by verifying the integrity of your install packages to determine what is trash or not.

Read this excellent article that explains the differences in the npm cache commands for more information.