npm's cache lives in Roaming on Windows, and only grows
Where npm, yarn and pnpm keep their caches on a PC, what each command actually clears, and which one is not a cache at all.
npm's cache is in a different place on Windows than on macOS, which is why half the advice you find does not match what is on your machine.
Where each one is
npm config get cache
corepack enable 2>$null
Get-ChildItem "$env:APPDATA\npm-cache","$env:LOCALAPPDATA\npm-cache","$env:LOCALAPPDATA\Yarn\Cache","$env:LOCALAPPDATA\pnpm\store" -EA SilentlyContinue |
ForEach-Object {
$s = (Get-ChildItem $_.FullName -Recurse -Force -File -EA SilentlyContinue | Measure-Object Length -Sum).Sum
'{0,8:N0} MB {1}' -f ($s/1MB), $_.FullName
}| Tool | Windows location | Command |
|---|---|---|
| npm | %APPDATA%\npm-cache | npm cache verify |
| Yarn classic | %LOCALAPPDATA%\Yarn\Cache | yarn cache clean |
| Yarn Berry | .yarn\cache in the project | yarn cache clean |
| pnpm | %LOCALAPPDATA%\pnpm\store | pnpm store prune |
verify rather than clean
The usual advice is npm cache clean --force, which empties everything. npm cache verify runs a garbage collect, removes entries that are no longer referenced, and deletes the cache's own temporary folder, which on a machine with interrupted installs is a surprising share of it. It reclaims most of the same space and leaves the useful entries in place.
pnpm's store is not a cache
Projects installed with pnpm hard link into the store, so removing it leaves existing installs pointing at files that are gone. pnpm store prune removes only what nothing references, which is the accumulation you want gone and none of the links you still need.
Where the space really is
Whatever these caches cost, the copies inside projects usually cost more, particularly on a machine that has used several package managers. node_modules across every project has the command, and the path length trap that goes with it on Windows.
Common questions
Where is the npm cache on Windows?
In %APPDATA%\npm-cache by default, which is different from macOS. Run npm config get cache to see the exact path your installation uses.
Should I use npm cache clean or verify?
verify. It garbage collects, drops unreferenced entries and clears the cache's temporary folder, reclaiming most of the same space without emptying everything.
Where does pnpm keep its store on Windows?
Under %LOCALAPPDATA%\pnpm\store. Projects hard link into it, so use pnpm store prune rather than deleting it, which would break existing installs.
Can I move the npm cache to another drive?
Yes, with npm config set cache followed by a path. On a machine with a small system drive that keeps a growing cache off C entirely.