nx/docs/shared/recipes/troubleshoot-cache-misses.md
Miroslav Jonaš a94bc7618a
docs(nx-dev): update troubleshoot-cache-misses.md (#28292)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2025-02-20 12:18:02 +00:00

2.2 KiB

Troubleshoot Cache Misses

Problem: A task is being executed when you expect it to be replayed from the cache.

Check 1: Check if your task is marked as cacheable:

  • Check the task has a "Cacheable" label in the Project Details View. You can do so by running nx show project <project-name> --web or by checking it in Nx Console.
  • If you're using a version lower than Nx 17.2.0, check:
    • the target configuration in the project's project.json file has "cache": true set, or
    • the target configuration in nx.json#targetDefaults has "cache": true set, or

Check 2: Check if the output of your task is changing the inputs of your task

  • Check the inputs and namedInputs defined in the project configuration and root nx.json. The inputs control whether a task will execute or replay from cache.
  • Check to see if there is an output file that is not being captured by the outputs for the task. The outputs property only controls what files are replayed from the cache, it doesn't dictate whether the cache is replayed, but an unaccounted output file could be modifying one of the inputs of the task.
  • To check your input glob patterns file-by-file, you can get a list of all the files associated with each project by running nx graph --file=output.json or by clicking on a task in the task graph in the nx graph visualization.

Check 3: Use the Nx Cloud troubleshooting tools

{% youtube src="https://youtu.be/zJmhW1iIxpc" title="Debug remote cache misses with Nx Cloud" /%}

  • Make sure your repo is connected to Nx Cloud
  • Click on the run details link that is printed in the terminal after you run a task
  • Click on the task with cache miss that you want to investigate
  • Click the "Compare to similar tasks" link in the top right corner of the task details
  • Select one of the similar tasks from the list in the "Compare to" section (or paste a URL of another run)
  • Nx Cloud will compare the input details of both tasks and will highlight all the differences
  • Note: Nx Cloud cannot access your source code, so it can only tell you which inputs are different based on their saved content hash, but not the exact git diff of the source code.