If you ever get weird errors in npm like “Please run npm cache clean” you may need to clean or refresh your npm cache.

When you install npm packages on your computer, npm will first add the packages and dependencies in your local npm cache folder. This will be ~/.npm on Posix, or %AppData%/npm-cache on Windows, according to the npm documentation.

Then npm will install the packages into the local project’s node_modules folder.

Then, in the future, if you install any of the same packages, npm will install them from your cache directly instead of having to download them from npm again.

However, sometimes the cache can get corrupted if different versions of dependencies are installed and conflict with one another. Clearing the cache will let you install the packages from npm again and have a fresh start.

To fix this, you can try running :

 npm cache clean

Run: “npm cache verify” for npm version 5 and up

However if you’re running npm v5 and above, npm is supposed to be self-healing, and you may get the following error message when trying to clean the npm cache:

So if you get that error, try running :

npm cache verify

If that doesn’t solve your problem, you can also try deleting the node_modules folder in your project and re-running "npm install".

Run: “npm cache clean –force”

And if npm cache clean and  npm cache verify. are both not working and you still can’t clear the cache, you can force clear the cache by running:

npm cache clean --force 
//or 
npm cache clean -f

This will force delete the npm cache on your computer.

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist

Leave a Reply

Your email address will not be published. Required fields are marked *