Yarn cache large disk usage

It took 30GB prior to the time I cleared the cache

Problem

My primary drive, which boots the operating system, went below 500MB free of 136GB space

For a long time before, I blamed the amount comsumption for the usage of other applications

I gradually moved applications to another drive, and occasionally

  • clear temporary files
  • empty recycle bin
  • remove unused application

Time passed, and the problem still persisted. Then one day, it really bugged my work

  • installing dependencies on a new project could shut down the machine
  • using many web brower's tabs could lead to

Again, I usually had to remind myself of

  • removing unused node_modules of old projects (during this I discovered npkill, which made removing these node_modules easier)
  • close unused tabs, or even turned off the brower to clear all the cache that comsumption the remaining low disk space

Also, I purchased exteral storage to move the data there and merged partitions to the main primary driver to add more space

Time pass, the problem still persisted..

No more guessing, I searched online for a tool to check disk space usage of my drive and I found TreeSize (Windows application, for other OS, you could search for other solution of the same purpose)

And after minutes of scanning, it turned out that yarn folder took 30GB

Root cause

According to Classic Yarn (Yarn v1) doc

Yarn stores every package in a global cache in your user directory on the file system

Long story, short discovery

Solution

Yes, clear the cache, and it is safe. It will took some minutes depending on the cache size

1yarn cache clear

Consider migrating to the latest version of yarn. In this new version

  • by default, cache is configured to be local to project
  • cache strategy is enhanced
  • installing performance is improved

Comments

Loading comments...

Tags

dev env

cli

yarn

Next Post

LeetCode: Make Array Zero by Subtracting Equal Amounts

Count non-zero unique numbers

Previous Post

HoningJS

Search Posts