How to clear the pnpm Store/Cache on MacBook
Need the right pnpm clear cache command? If you’ve been shocked at just how many gigabytes its store seems to have racked up, considering it’s meant to be the package manager that saves disk space, you’re definitely not alone here.
pnpm works by keeping one shared package store and linking those files into each project’s node_modules, rather than saving a full copy for every project, but when a package stops being used, there’s nothing working to automatically clean this up, hence why it gets so big.
I’ll show you the safe command you need in the section below to prune, plus some extras.
pnpm store prune
All you need to do is run: pnpm store prune
Good to know, this won't work while a store server is running. But if everything is in order, it’ll remove only packages no longer referenced by any project on your machine. (not any currently project-referenced packages) It’s safe and won’t affect your projects. Anything that is pruned is automatically re-downloaded if a future install needs it.
I wouldn’t start pruning daily; it's just not needed. I’d actually use it a bit more strategically; for example, pruning right before switching to an old branch means you’ll have to re-download everything you just removed.
Pnpm store size and where it’s all saved
One thing I’ve learned along the way is to never hardcode the pnpm store path, because it can change between pnpm versions, so I’d always just ask pnpm directly with: pnpm store path
Normally, its location on your macOS is here: ~/Library/pnpm/store/<version> and that version segment at the end will change between pnpm majors, which is why the dynamic command matters.
If you want to check size, use this: du -sh $(pnpm store path)
It’s also useful to check integrity too, which you can with this: pnpm store status
After any major pnpm upgrades, you’ll probably notice that the old store directory hangs around. I try to periodically check for dead version folders with: ls ~/Library/pnpm/store/
Pnpm store vs. pnpm cache
The store holds all the package content hard-linked into your projects. You can manage it with: pnpm store prune and cache holds all your registry metadata, like available package versions and download information.
Good to know, cache commands for pnpm can vary between major versions, so always first check your installed version first: pnpm --version
npm's cache: what’s the difference?
If you’ve switched from npm, then I bet you’ve been caught out by this.
npm and pnpm do work differently. As I’ve already mentioned, pnpm keeps packages in one shared store and then goes on to link them into each project, while npm works by caching package downloads, then installing a separate unpacked copy inside each project’s node_modules.
Cleanup works differently, too. Deleting node_modules will probably free up almost no space because the package files still live in pnpm’s shared store. To reclaim that space, run: pnpm store prune
For more tips on npm clean cache, jump to this guide on how to clear npm cache on Mac.
Can you rebuild the pnpm store?
If pnpm store prune just isn’t enough, you can remove the store completely and let pnpm rebuild it from scratch with: rm -rf $(pnpm store path)
But it’s really only a last-resort move, so just spend a moment and really think if this is necessary; every project on your machine will need to re-download everything on the next install.
You’ll then need to reinstall dependencies with these two commands:
-
rm -rf node_modules
-
pnpm install
Word of caution here: never delete the store directory while an install is running.
Pnpm store prune issues
If you’re running pnpm store prune but no space is freeing up, that pretty much always means everything in the current store is still referenced. You need to check the store first: pnpm store status
Also look for dead store folders left behind by older pnpm versions.
Another common issue is that after pruning, users report their disks are still full. Check old node_modules folders, caches from other package managers, and don’t forget pnpm’s metadata cache.
Permission errors will require you to fix ownership instead of running pnpm with sudo: sudo chown -R $(whoami) $(pnpm store path)
If pnpm keeps re-downloading packages, you’ll have to check if a project is using a different store path with: pnpm config get store-dir
And if hard links aren’t working, it’s possible that the project and pnpm store are on different filesystems.
The rest of the dev caches on your Mac
Over the years I’ve come to think that yes, it can help to prune your pnpm, but honestly, it’s most likely not the only culprit on a busy dev machine. You’ll also need to check your ~/.npm, Yarn cache, ~/Library/Caches/Homebrew, ~/Library/Developer/Xcode/DerivedData, actually, this list can go on. Even orphaned node_modules folders in projects you abandoned are their own category.
If cleaning all of this up in one go without even leaving the shell sounds like a dream come true, well, there’s a new tool still in public beta from MacPaw, called CleanMyMac CLI, which can do just that.
You can install it the way you install everything else with: brew install --cask cleanmymac-cli
Then the cleanmymac clean dev command covers pnpm, npm, Yarn, pip, Cargo, Homebrew, Docker, Xcode, and JetBrains caches in one. I also like the cleanmymac purge command; it hunts down orphaned node_modules folders across your project directories, and cleanmymac analyze gives you an interactive view of what's taking up space before you delete anything.
So that’s all the pnpm clear cache commands worth knowing.