How to clear nx cache

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 4, 2026

Quick Answer: To clear the Nx cache, you can use the `nx reset` command in your project's root directory. This command will delete all files in the `.nx/cache` directory, effectively clearing the cache.

Key Facts

What is the Nx Cache?

Nx is a smart, extensible build system for monorepos. One of its core features is its powerful caching mechanism. The Nx cache stores the results of tasks (like building, testing, linting, etc.) that have been executed. When you run a command again, Nx checks if the inputs to that command (source code, configuration files, dependencies) have changed. If they haven't changed, Nx serves the result directly from the cache, saving significant time and computational resources. This is particularly beneficial in large monorepos where rebuilds can be very time-consuming.

Why Would You Need to Clear the Nx Cache?

While the Nx cache is designed to be reliable, there are several scenarios where clearing it might be necessary:

How to Clear the Nx Cache

The most straightforward and recommended way to clear the Nx cache is by using the Nx CLI command:

Using `nx reset`

Navigate to the root directory of your Nx workspace in your terminal. Then, execute the following command:

nx reset

This command performs the following actions:

After running `nx reset`, the next time you execute an Nx command (e.g., `nx build my-app`, `nx test my-lib`), Nx will have to recompute all the affected targets. This means the first run after clearing the cache will be slower than usual, as it won't be able to leverage any cached results.

Manual Deletion (Not Recommended)

While technically possible, manually deleting the contents of the `.nx/cache` directory is not the recommended approach. The `nx reset` command is safer as it's designed specifically for this purpose and ensures Nx handles the cache cleanup appropriately. Manual deletion might sometimes lead to unexpected issues if not done correctly.

What Happens After Clearing the Cache?

Once the Nx cache is cleared:

Best Practices

Clearing the Nx cache should generally be done only when necessary. Frequent cache clearing can negate the performance benefits of using Nx. Consider clearing the cache primarily for troubleshooting or when you suspect cache-related issues. For regular development, trust Nx's caching mechanism to speed up your workflow.

If you are experiencing persistent issues that you believe are cache-related, try running `nx reset` and then performing the operation again. If the problem persists, the issue might lie elsewhere in your project configuration or code.

Sources

  1. Nx CLI Commands: resetCC-BY-NC-4.0
  2. Nx Caching ConceptCC-BY-NC-4.0

Missing an answer?

Suggest a question and we'll generate an answer for it.