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!
- How to Install Node on Windows, macOS and Linux
- How to deploy a .NET app using Docker
- Getting Started with Deno
- How to deploy an Express app using Docker
- How to deploy a Node app using Docker
- Getting Started with Sass
- Using Puppeteer and Jest for End-to-End Testing
- Getting Started with Moment.js
- Learn how to build a Slack Bot using Node.js
- Creating a Twitter bot with Node.js
- Using Axios to Pull Data from a REST API
- How To Create a Modal Popup Box with CSS and JavaScript