nextjs
config_error
ai_generated
true
Error: fetch failed with 'no-store' and 'use cache' directive conflict
ID: nextjs/use-cache-no-store-fetch
90%Fix Rate
85%Confidence
1Evidence
2025-01-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| [email protected] | active | — | — | — |
| [email protected] | active | — | — | — |
Root Cause
When a component or function uses the 'use cache' directive to enable caching, but the fetch call inside it uses 'cache: no-store', Next.js throws an error because the two caching strategies are incompatible.
generic中文
当组件或函数使用 'use cache' 指令启用缓存,但内部的 fetch 调用使用了 'cache: no-store' 时,Next.js 会抛出错误,因为两种缓存策略不兼容。
Official Documentation
https://nextjs.org/docs/app/api-reference/directives/use-cacheWorkarounds
-
90% success Remove 'cache: no-store' from the fetch call and rely on the 'use cache' directive for caching behavior. If fresh data is needed, use revalidation options like 'next: { revalidate: 0 }'.
Remove 'cache: no-store' from the fetch call and rely on the 'use cache' directive for caching behavior. If fresh data is needed, use revalidation options like 'next: { revalidate: 0 }'. -
80% success Move the fetch call outside the 'use cache' scope by extracting it to a separate function without the directive.
Move the fetch call outside the 'use cache' scope by extracting it to a separate function without the directive.
中文步骤
从 fetch 调用中移除 'cache: no-store',依赖 'use cache' 指令的缓存行为。如果需要新鲜数据,使用 'next: { revalidate: 0 }' 等重新验证选项。将 fetch 调用移到 'use cache' 作用域之外,提取到没有该指令的单独函数中。
Dead Ends
Common approaches that don't work:
-
60% fail
This disables caching for the entire component, which may degrade performance and is not always necessary.
-
80% fail
This forces caching even when fresh data is needed, leading to stale responses.