Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yarn cache takes a lot of space

I was shocked few minutes ago when I figured it out that Yarn cache on location /Users/user/Library/Caches/Yarn takes more than 50GB of my disk space. What the heck? Why is there every existing package in this universe on my computer? I am glad that Yarn advertise itself as ultra fast, but in compensation with eating that much disk space I am not fan anymore. Now I even understand why yarn cache clean takes years to finish its job.

Does Yarn cache all versions of particular package? Are there any plans in Yarn dev team to implement some kind of warning that cache is taking a lot of space and it could be cleared?

like image 684
Marek Avatar asked Oct 23 '18 17:10

Marek


People also ask

Is it safe to clear yarn cache?

In addition to the answer, $ yarn cache clean removes all libraries from cache. If you want to remove a specific lib's cache run $ yarn cache dir to get the right yarn cache directory path for your OS, then $ cd to that directory and remove the folder with the name + version of the lib you want to cleanup.

What is yarn cache?

yarn cache list [--pattern] Yarn stores every package in a global cache in your user directory on the file system. yarn cache list will print out every cached package. yarn cache list --pattern <pattern> will print out every cached package that matches the pattern provided.

Where does yarn store its cache?

yarn currently save cached packages in a default directory: /Users/<user>/Library/Caches/yarn or C:/Users/<user>/AppData/Local/Yarn/cache . When a lot of packages are cached, each user on the system to consume a lot of space on the primary drive.


1 Answers

Yarn website says the following:-

Yarn stores every package in a global cache in your user directory on the file system. 
  1. You can use yarn cache list & it will print out every cached package. Just in case you wanted to go through.
  2. You can use yarn cache clean & it will clean the cache (Note that it's a time taking process and considering your cache size this will be forever!)
  3. You can use yarn cache dir and it will display the path where it's storing the cache! You know what to do next, use rm -rf yarn-cache-dir this will free up your space and clear all the cache as well.

Note generally your yarn cache dir can be found at ~/.cache/yarn/. In my system the cache is stored in ~/.cache/yarn/v6/.

UPDATE:- It's recommended to use latest version of yarn.

like image 70
Viraj Shelke Avatar answered Oct 13 '22 00:10

Viraj Shelke