How to clear your cache in npm
If you ever get weird errors in npm like
Please run npm cache clean you may need to clean or refresh your npm cache.
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:
npm ERR! As of [email protected], 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. npm ERR! npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force.
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
Run: “npm cache clean –force”
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.
What does npm cache clean do?
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
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.
I'm making a course that will teach you how to build a real-world responsive website from scratch!Learn more