Skip to cookie settings

npm, Yarn and pnpm caches: where they live and how to clean them

Each JavaScript package manager keeps its own download cache. Here is how to find each one and what clearing it costs.

Part of: Mac disk cleanup for developers: every cache, what it costs to rebuild (Developers)

Each JavaScript package manager has a command that prints its cache path. For npm it is npm config get cache, for Yarn yarn cache dir, and for pnpm pnpm store path. The npm and Yarn caches are safe to remove: the tool downloads packages again when it needs them. The pnpm store is riskier, because your projects link to files inside it, so removing it can break node_modules folders until you reinstall.

The caches hold copies of packages you installed before. They make the next install faster. They are separate from the node_modules folder inside each project, which is covered in finding every node_modules folder.

Find each cache

npm config get cache
yarn cache dir
pnpm store path

Run the ones for the tools you use. On the Mac used to check this article they printed ~/.npm, a folder in ~/Library/Caches/Yarn/v6 and a pnpm store folder in ~/Library/pnpm/store/v10. Yours may differ, because package managers change their defaults between versions and you can set your own path.

To see the sizes:

du -sh ~/.npm ~/Library/Caches/Yarn "$(pnpm store path)"

Folders that do not exist on your Mac print an error. That is fine. On the Mac used to check this, the npm cache was a few hundred megabytes at most, and the Yarn one was empty.

What each cache holds

  • npm: the _cacache folder inside ~/.npm holds downloaded package files and metadata in a content-addressed format, which means files are named by a checksum, not by package name. You cannot browse it by name.
  • Yarn: a folder of package archives, one per package version. Classic Yarn and newer Yarn versions store them differently, so check which you use.
  • pnpm: one shared store of package files. Projects link to it, so a package installed in ten projects is stored once.

Safe, risky, never

  • Safe: the whole npm cache or the whole Yarn cache. Cost: the next install downloads packages again.
  • Risky: the pnpm store when your projects depend on it right now. Projects link to files in it. If you remove the store, node_modules folders that point into it can break until you reinstall.
  • Never: do not edit files inside a cache by hand, and do not delete a project’s lock file as part of a cleanup. The lock file records your versions.

What it costs

Clearing a cache costs downloads. The first install of each project afterwards fetches packages from the registry. If you are offline, or the registry is slow, installs fail or crawl. A clean cache also drops the safety net some teams rely on: if a package version is removed from the registry, the cache may be the last copy on your Mac.

pnpm needs the extra care described above, since it links into its store. The safest way to shrink a pnpm store is to use pnpm’s own tooling for removing packages that no project uses. See pnpm’s documentation, because options differ by version.

How to clear them

  1. Find each path with the commands above.
  2. Quit editors and dev servers that run installs.
  3. Use each tool’s own cache command, listed in its documentation, or move the cache folder to the Trash in Finder and empty it. The space comes back only after the Trash is emptied. See why the Trash does not free space.
  4. Run an install in a project and check that it works.

Which one to bother with

Sizes vary. The node_modules folders in your projects are usually larger than any cache, so start there. If one cache is large, clear that one. If you use only one package manager, the others are likely empty.

For other download caches see the Homebrew cache and the pip cache. The overall list is in the developer cleanup guide.

Worked example: size each cache

Here are the read-only numbers from the Mac used to check this article. The npm cache folder, ~/.npm/_cacache, was about 104 MB. The ~/.npm folder also held a few other folders, among them _logs and _npx. The _npx folder can grow large, so size it too. The Yarn cache folder existed as ~/Library/Caches/Yarn/v6.

To see what sits next to the cache in ~/.npm:

ls -a ~/.npm

Only _cacache is the package cache. The other items are logs and helper data. When you want to know how much you could free, measure _cacache, not the whole folder.

Check which versions you are running, because the paths and commands can change between them:

npm --version
yarn --version
pnpm --version

On that Mac these printed npm 11.19.1, Yarn 1.22.22 and pnpm 10.13.1. Yarn 1.x is the classic one mentioned above. Newer Yarn versions keep their cache in a different way, so check your own version before you act.

If something goes wrong

  • An install fails after clearing with a network error. The cache no longer has the package and you are offline. Reconnect.
  • A pnpm project says a module cannot be found. You removed the store while the project linked to it. Run the install in that project again.
  • A package that exists on your Mac cannot be installed anywhere else. It may have been removed from the registry. If you have a cached copy, keep it until you have a better one.
  • Disk space does not change. You moved the folder to the Trash and did not empty it.

When not to clean

Skip it when the caches are small. Do not clear the pnpm store while projects depend on it and you need them to run today.

See the sizes in a scan

DiskJoy is our product. Its scan reads your disk and shows how large these cache folders are, without changing anything. Cleanup is not built yet, so DiskJoy does not remove them today.

Frequently asked questions

Where is the npm cache on a Mac?

Run npm config get cache. By default it prints a path to a folder named .npm in your home folder, and the downloaded packages are in a _cacache folder inside it.

Why does Yarn take up so much space?

Yarn keeps a copy of each package it ever downloaded in a cache folder. Run yarn cache dir to find it. Old versions of packages stay until you clean it.

Where does pnpm store packages?

Run pnpm store path. On the Mac used to check this article it printed a folder inside the user Library folder. pnpm links files from this store into node_modules instead of copying them.

Tags:npmYarnpnpm

See what’s taking up space on your Mac

DiskJoy explains every item and removes nothing until you review it.
Download for Mac

Cookies on diskjoy.com

Your browser sends a Global Privacy Control signal. We honoured it: analytics and marketing cookies are off.

Necessary cookies run this site. Analytics shows us how it is used: if you accept it, Google receives data about your visit. Change this anytime in Cookie Settings. How Google uses data Cookie Policy Privacy policy

Customize

Purpose
Needed for the site to work and to remember your cookie choice.

Cookies

  • sy_consent - Stores your cookie choice (Retention: 12 months)

Other browser storage

  • sy_consent_pending (localStorage) - Queues your choice until it reaches our server (Retention: until deleted)
Purpose
Show us which pages are visited and how the site is used, so we can improve it. Provider: Google Ireland Ltd (Google Analytics 4).

Cookies

  • _ga - Distinguishes visitors to count them (Retention: 400 days)
  • _ga_TP2XMLG27P - Keeps the state of your current visit (Retention: 400 days)

Recipients

Data controller

Sylentis Group sp. z o.o.. Contact: support@diskjoy.com. Privacy policy

Google may process data outside the European Economic Area (EEA). Safeguards: EU-US Data Privacy Framework, standard contractual clauses.

Right to withdraw

You can withdraw consent at any time, as easily as you gave it. Withdrawal does not affect the lawfulness of processing before it.