ClearDisk
Buy for $10Download ClearDiskDownload
A LITTLE MORE CLARITY

Clear the Yarn and pnpm cache on Mac: where they live

Yarn 1 keeps one global cache (yarn cache dir), modern Yarn keeps a global cache in ~/.yarn/berry plus optional per-project caches, and pnpm keeps a shared store in ~/Library/pnpm/store. Clean each with its own command: yarn cache clean or pnpm store prune.

1. Work out which package manager and version

Yarn 1, often called Yarn classic, and modern Yarn, version 2 and later, store their caches in different places and use different commands. Run yarn --version inside a project: a 1.x number means classic. A packageManager field in package.json, or a .yarnrc.yml file in the project, is another sign the project uses modern Yarn.

pnpm --version confirms pnpm. Clearing the cache of a tool a project does not use frees nothing for that project, so check each project you care about rather than assuming one version across the Mac.

yarn --version
pnpm --version

2. Yarn 1: one global cache

Yarn 1 keeps every package it downloads in a single global cache. yarn cache dir prints its location, which on a Mac is usually inside ~/Library/Caches/Yarn, and du measures it. yarn cache list shows what is stored, and its --pattern option filters the list by package name.

yarn cache clean clears the whole cache, and a package name after it clears only that package. The documentation notes the cache is populated again the next time yarn or yarn install runs, so the cost is a slower, network-dependent first install.

yarn cache dir
du -sh "$(yarn cache dir)"
yarn cache clean

3. Modern Yarn: a global cache and project caches

Modern Yarn’s enableGlobalCache setting is true by default, which stores cache files in its global folder, ~/.yarn/berry unless configured otherwise. A project that sets enableGlobalCache to false uses its cacheFolder instead, by default .yarn/cache inside the project.

That project cache is often committed to git on purpose, for offline installs or the setup Yarn calls Zero-Installs. Deleting it from a repository shows up as deleted files in version control, so leave a committed .yarn/cache alone. Run yarn cache clean in a project to clear its local cache, --mirror to clear the global cache instead, or --all for both.

du -sh ~/.yarn/berry
yarn cache clean --mirror

4. pnpm: one store per disk

pnpm keeps packages in a content-addressable store; pnpm’s documentation gives ~/Library/pnpm/store as the default on macOS, and pnpm store path prints the one in use. The store should be on the same disk as your projects, so pnpm uses one store per disk: projects on an external drive get a separate .pnpm-store folder at the root of that drive.

pnpm store prune removes packages that no project on the system references any more. pnpm describes it as harmless with no side effects on projects, and suggests running it occasionally rather than often, because switching branches can need an unreferenced package again, and pnpm then downloads it.

pnpm store path
du -sh "$(pnpm store path)"
pnpm store prune

Why node_modules sizes mislead with pnpm

pnpm links or clones files from the store into each project’s node_modules instead of copying them, so a project folder and the store share the same data. Adding a project’s node_modules size to the store size counts that data twice, and deleting one project’s node_modules frees little on its own.

The order that works is to delete node_modules in projects you have finished with, then run pnpm store prune so packages nothing references are removed. ClearDisk’s Developer Junk list covers the npm cache and node_modules folders but not the Yarn or pnpm stores; its storage map and search show their sizes, and the commands above do the cleanup.

Do not delete the store folder itself in Finder. Projects that link into it may then need a full reinstall, and pnpm has no way to tell which packages you still wanted. pnpm store status checks whether packages in the store have been modified since they were unpacked, which is worth running if you suspect a damaged store.

Common questions

How do I know if a project uses Yarn 1 (classic) or modern Yarn?

Run yarn --version: a 1.x number means classic. A packageManager field in package.json or a .yarnrc.yml file signals modern Yarn, version 2 or later, and each version stores and clears its cache differently.

Is it safe to delete a project's committed .yarn/cache folder?

Not if your team commits it to git on purpose, for offline installs or Zero-Installs. Deleting it shows up as deleted files in version control, so leave a committed .yarn/cache alone.

Why doesn't deleting a project's node_modules free much space with pnpm?

pnpm links or clones files from its shared store into each project's node_modules instead of copying them, so the project folder and the store share the same data, and deleting one node_modules frees little on its own.

Can I delete pnpm's store folder directly in Finder?

No. Projects that link into it may then need a full reinstall, and pnpm has no way to know which packages you still wanted. Use pnpm store prune instead to remove only unreferenced packages.

References & further reading

These guides combine the linked official guidance with ClearDisk’s documented behavior. Your files and app settings determine the right next step.

Main guide: developer storage on Mac · Related pillar: clear Xcode Derived Data on Mac · Browse all Developer storage guides →

FROM A NUMBER TO AN ANSWER

See what’s using
your space.

Explore your Mac with ClearDisk’s free local scanner.
Review the files. Keep the control.

Download free scannermacOS 15+ · version 2.2.1Cleanup license: $10 once