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
- 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;
- 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
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 });
}
Current Behavior
Nx doesn't cache failures, even with the
NX_CACHE_FAILURESflag 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_FAILURESis enabled.GitHub Repo
https://github.com/glypse/nx-failures-not-cached
Steps to Reproduce
lint), runNX_CACHE_FAILURES=true npm nx run [PACKAGE]:lintwhere the lint fails;Nx Report
Failure Logs
Package Manager Version
No response
Operating System
Additional Information
Issue might arise from
nx/packages/nx/src/tasks-runner/task-orchestrator.ts
Line 484 in 0596b18
NX_CACHE_FAILURESisn't taken into account. Fix might look something like: