nextjs config_error ai_generated true

错误:fetch 使用了 'no-store' 与 'use cache' 指令冲突

Error: fetch failed with 'no-store' and 'use cache' directive conflict

ID: nextjs/use-cache-no-store-fetch

其他格式: JSON · Markdown 中文 · English
90%修复率
85%置信度
1证据数
2025-01-10首次发现

版本兼容性

版本状态引入弃用备注
[email protected] active
[email protected] active

根因分析

当组件或函数使用 'use cache' 指令启用缓存,但内部的 fetch 调用使用了 'cache: no-store' 时,Next.js 会抛出错误,因为两种缓存策略不兼容。

English

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

官方文档

https://nextjs.org/docs/app/api-reference/directives/use-cache

解决方案

  1. 从 fetch 调用中移除 'cache: no-store',依赖 'use cache' 指令的缓存行为。如果需要新鲜数据,使用 'next: { revalidate: 0 }' 等重新验证选项。
  2. 将 fetch 调用移到 'use cache' 作用域之外,提取到没有该指令的单独函数中。

无效尝试

常见但无效的做法:

  1. 60% 失败

    This disables caching for the entire component, which may degrade performance and is not always necessary.

  2. 80% 失败

    This forces caching even when fresh data is needed, leading to stale responses.