DevCleaner
Menu
Skip to content
Browse guides

How to clear npm cache (npm cache clean --force)

The npm cache is a download cache. Clearing it does not delete node_modules. Packages come back from the registry on the next install.

On this page

Check the cache first

On a Mac the usual location is ~/.npm, often 2 to 10 GB. Confirm the path your npm is actually using, then measure it:

npm config get cache
du -sh ~/.npm

Custom settings can move the cache. npx keeps a separate execution cache at ~/.npm/_npx (often 0.5 to 2 GB). Check npm cache --help before assuming a package-cache cleanup removed it.

npm cache clean --force

npm cache clean --force

This cache is SAFE. The --force flag is the form npm requires, not a sign that the cache is dangerous. The gentler option checks integrity and garbage-collects unneeded data:

npm cache verify

The .npm tree can also include logs and npx state. The package cache itself is regenerable.

node_modules is separate

Forgotten node_modules folders are often larger than the global cache. Deleting them is a different decision, and it depends on the lockfile. That is covered in can I delete node_modules?

Yarn and pnpm have their own stores: how to clear yarn cache and how to clear pnpm cache. The overview is npm, yarn, and pnpm cache.

FAQ

Is npm cache clean --force safe?
Yes. The npm package cache is regenerable. The --force flag is the form npm requires, not a warning that the cache is dangerous. npm cache verify is the gentler option: it checks integrity and garbage-collects unneeded data. The .npm folder can also hold logs and npx state.
Does clearing the npm cache delete node_modules?
No. npm cache clean --force clears the download cache, usually ~/.npm. node_modules stays in the project. See the node_modules guide if that folder is what you want to remove.

Scan it with DevCleaner

DevCleaner measures the npm cache next to Yarn, pnpm, and the rest of your developer tools, and shows the size before anything is deleted. Safe cleanup is free.

Download DevCleaner ↓

References and scope

Commands and paths are the ones already published in the combined npm, Yarn, and pnpm guide, reviewed against the npm cache reference. Paths depend on npm version and configuration. Size ranges are illustrative, not a recovery guarantee. Check npm cache --help on your machine before you run a cleanup.