Table of Contents
Yarn is a powerful and popular tool for managing the dependencies of your Node project.
It is an alternative to npm
, which is the default package manager for Node.
Every time you install a new package using yarn add
, Yarn will store a copy in its cache directory.
This cache is used to speed up your next yarn add
command, however sometimes it can be useful to clear the cache to regain back some storage space.
In this post, we'll learn how to clear the Yarn cache.
Clearing the Yarn Cache
As mentioned before, the cache is created by Yarn as you install the packages for your project.
The default cache directory is ~/.yarn-cache
, however, rather than directly modifying this folder, it is safer to use the built-in Yarn commands specifically for clearing the cache.
To clear the cache, run the following command:
BASHyarn cache clean
This command will clear the entire Yarn cache for you, wiping out all packages.
You can, however, clear the cache selectively by specifying the packages you want to remove.
You can do this by specifying the packages you want to remove, separated by a space.
For example, here's how to clear the cache for React:
BASHyarn cache clean react
You can also list out the cache for all the packages currently cached by running this command:
BASHyarn cache list
From there, you can choose to selectively remove packages, or you can remove all packages at once.
Conclusion
In this post, we've learned how to clear the Yarn cache, both in a simple way and selectively.
We even learned how to list out the cache for all the packages currently cached by Yarn.
Hopefully, this helps you get a better handle on your Yarn cache. Thanks for reading!
- Getting Started with Svelte
- Getting Started with Express
- How to Serve Static Files with Nginx and Docker
- Best Visual Studio Code Extensions for 2022
- Getting Started with Deno
- How to deploy an Express app using Docker
- Learn how to use v-model with a custom Vue component
- Using Puppeteer and Jest for End-to-End Testing
- How to Scrape the Web using Node.js and Puppeteer
- Learn how to build a Slack Bot using Node.js
- Using Push.js to Display Web Browser Notifications
- Setting Up Stylus CSS Preprocessor