Skip to content

NX_CACHE_FAILURES is ignored #35901

@glypse

Description

@glypse

Current Behavior

Nx doesn't cache failures, even with the NX_CACHE_FAILURES flag enabled.
According to my (very non-trustworthy, junior dev here) research, more precisely, Nx stores failed cache but never reads from it.

Expected Behavior

For Nx to cache and read from cache failed tasks when NX_CACHE_FAILURES is enabled.

GitHub Repo

https://github.com/glypse/nx-failures-not-cached

Steps to Reproduce

  1. In an Nx project configured with cache enable on the command (in this example lint), run NX_CACHE_FAILURES=true npm nx run [PACKAGE]:lint where the lint fails;
  2. Run the same command again: the whole linting happens again without using cache.

Nx Report

Node           : 26.0.0
OS             : darwin-arm64
Native Target  : aarch64-macos
bun            : 1.3.14
daemon         : Available

nx                 : 22.7.5
@nx/js             : 22.7.5
@nx/eslint         : 22.7.5
@nx/eslint-plugin  : 22.7.5
@nx/vite           : 22.7.5
@nx/web            : 22.7.5
typescript         : 6.0.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/vite/plugin
@nx/eslint/plugin
---------------------------------------
Cache Usage: 956.00 B / 22.83 GB

Failure Logs

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Issue might arise from

if (cachedResult && cachedResult.code === 0) {
, where NX_CACHE_FAILURES isn't taken into account. Fix might look something like:

if (cachedResult &&
    (cachedResult.code === 0 || process.env.NX_CACHE_FAILURES == 'true')) {
    cacheHits.push({ task, cachedResult });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions