{"id":2045,"date":"2022-07-20T11:50:19","date_gmt":"2022-07-20T09:50:19","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=2045"},"modified":"2022-07-20T11:53:22","modified_gmt":"2022-07-20T09:53:22","slug":"how-to-clear-your-cache-in-npm","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2022\/07\/20\/how-to-clear-your-cache-in-npm\/","title":{"rendered":"How to clear your cache in npm"},"content":{"rendered":"\n<p>If you ever get weird errors in npm like&nbsp;&#8220;<code><em><span class=\"has-inline-color has-vivid-cyan-blue-color\">Please run npm cache clean<\/span><\/em><\/code>&#8221;&nbsp;you may need to clean or refresh your npm cache.<\/p>\n\n\n\n<p>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&nbsp;<em><span class=\"has-inline-color has-vivid-cyan-blue-color\"><code>~\/.npm<\/code>&nbsp;<\/span><\/em>on Posix, or&nbsp;<code><em><span class=\"has-inline-color has-vivid-cyan-blue-color\">%AppData%\/npm-cache<\/span><\/em><\/code>&nbsp;on Windows, according to the&nbsp;<a href=\"https:\/\/docs.npmjs.com\/cli\/v7\/commands\/npm-cache\">npm documentation<\/a>.<\/p>\n\n\n\n<p>Then npm will install the packages into the local project\u2019s&nbsp;<code><em><span class=\"has-inline-color has-vivid-cyan-blue-color\">node_module<\/span><\/em>s<\/code>&nbsp;folder.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>To fix this, you can try running :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> npm cache clean<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4>Run: \u201cnpm cache verify\u201d for npm version 5 and up<\/h4>\n\n\n\n<p>However if you\u2019re 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:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"726\" height=\"148\" src=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/07\/image-12.png\" alt=\"\" class=\"wp-image-2046\" srcset=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/07\/image-12.png 726w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/07\/image-12-300x61.png 300w\" sizes=\"(max-width: 726px) 100vw, 726px\" \/><\/figure><\/div>\n\n\n\n<p>So if you get that error, try running : <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm cache verify<\/code><\/pre>\n\n\n\n<p>If that doesn\u2019t solve your problem, you can also try deleting the&nbsp;<code><em><span class=\"has-inline-color has-vivid-cyan-blue-color\">node_modules<\/span><\/em><\/code>&nbsp;folder in your project and re-running<em><span class=\"has-inline-color has-vivid-cyan-blue-color\">&nbsp;<code>\"npm install\"<\/code>.<\/span><\/em><\/p>\n\n\n\n<h4>Run: \u201cnpm cache clean \u2013force\u201d<\/h4>\n\n\n\n<p>And if&nbsp;<code>npm cache clean<\/code>&nbsp;and &nbsp;<code>npm cache verify<\/code>. are both not working and you still can\u2019t clear the cache, you can force clear the cache by running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm cache clean --force \n\/\/or \nnpm cache clean -f<\/code><\/pre>\n\n\n\n<p>This will force delete the npm cache on your computer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you ever get weird errors in npm like&nbsp;&#8220;Please run npm cache clean&#8221;&nbsp;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&nbsp;~\/.npm&nbsp;on Posix, or&nbsp;%AppData%\/npm-cache&nbsp;on Windows, according to the&nbsp;npm documentation. Then [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2048,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,453],"tags":[342,344,161,217],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2045"}],"collection":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=2045"}],"version-history":[{"count":2,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2045\/revisions"}],"predecessor-version":[{"id":2049,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2045\/revisions\/2049"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/2048"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=2045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=2045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=2045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}