One thing people may not realize, even if they’re seasoned frontend devs - your Yarn cache is bigger than you think. Have you ever looked at your Yarn cache?
A few months ago at work, my laptop’s 500GB SSD was mysteriously nearly full - I didn’t understand how that was possible! I only had about 1.5GB of my own stuff, as far as I knew.
Long story short, my Yarn cache directory was huge. Please, take a moment and guess how big you think a Yarn cache could be.
Yarn stores every package in a global cache in your user directory on the file system.
Before I answer how big my Yarn cache is, let’s check yours out!
To get the current size of your Yarn cache, run the following in your terminal: (it may take quite a while!)
du -hcs $(yarn cache dir)
Want to get rid of your enormous cache? Just run the following:
yarn cache clean
But… it’s not always that simple.
If your Yarn cache is massive (easy to do!), you will encounter a heap error.
The only effective solution I found is to run the following:
rm -rf $(yarn cache dir)
This can potentially take hours (yes, really).
Even after deleting my cache in August, it’s only two months later now, and it’s back up to 268GB