How to clear your cache in npm - Coder Coder (2024)

If you ever get weird errors in npm likePlease run npm cache cleanyou may need to clean or refresh your npm cache.

To fix this, you can try runningnpm 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 npm@5, 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 runningnpm cache verify.

If that doesn’t solve your problem, you can also try deleting thenode_modulesfolder in your project and re-runningnpm install.

Run: “npm cache clean –force”

And ifnpm cache cleanand 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 --forceornpm 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~/.npmon Posix, or%AppData%/npm-cacheon Windows, according to thenpm documentation.

Then npm will install the packages into the local project’snode_modulesfolder.

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.

Want to learn how to build a website?

I'm making a course that will teach you how to build a real-world responsive website from a Figma design!

Learn more

How to clear your cache in npm - Coder Coder (2024)
Top Articles
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 5970

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.