The Nx cache: every task output in your monorepo, kept until you clear it
Nx stores the output of every cached build, test and lint run so it can replay them. In a busy monorepo it can outgrow node_modules. How to size and clear it.
Nx makes repeat builds fast by caching the outputs of tasks: compiled code, test results, lint output. When the same task runs with the same inputs, Nx restores the files instead of running it. Every distinct result is stored, and in a monorepo with many projects and frequent changes that is a lot of results.
Where it is
Recent Nx versions keep the cache in .nx/cache at the root of the workspace. Older versions used node_modules/.cache/nx. Check both:
cd ~/code/your-monorepo
du -sh .nx/cache node_modules/.cache/nx 2>/dev/nullAcross every workspace on your Mac:
find ~/code -type d \( -path '*/.nx/cache' -o -path '*/node_modules/.cache/nx' \) -prune -exec du -sh {} + 2>/dev/null | sort -hClearing it
npx nx resetnx reset clears the local cache and stops the Nx background process. The next run of each task takes its full time once. If your team uses a remote cache, those results are fetched again rather than rebuilt.
Keeping it smaller
- Make sure task outputs are declared accurately. A task that lists a whole folder as output caches everything in it.
- Check whether your Nx version supports a maximum cache size setting in
nx.json. Where it does, it removes the oldest entries for you. - Clear it before archiving an old project.
Other monorepo and frontend tools keep similar caches. See frontend build caches for Turborepo, Next.js and Vite, and node_modules.
Common questions
Where is the Nx cache stored?
In .nx/cache at the workspace root in recent Nx versions, and in node_modules/.cache/nx in older ones.
How do I clear the Nx cache?
Run npx nx reset in the workspace. It clears the local cache and stops the Nx background process. Each task runs in full once afterwards.
Is it safe to delete the Nx cache?
Yes. It only holds results Nx can recreate by running the tasks again, or fetch again from a remote cache if you use one.