{
  "id": "nextjs/invariant-requestAsyncStorage-not-available",
  "signature": "Error: Invariant: headers() expects to have requestAsyncStorage, but none is available.",
  "signature_zh": "错误：不变量：headers() 期望有 requestAsyncStorage，但当前不可用。",
  "regex": "Error: Invariant: headers\\(\\) expects to have requestAsyncStorage, but none is available\\.",
  "domain": "nextjs",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The headers() function is called outside of a valid request context, such as in a synchronous function, a utility file, or a component that runs during build time without a request.",
  "root_cause_type": "generic",
  "root_cause_zh": "headers() 函数在有效的请求上下文之外被调用，例如在同步函数、实用程序文件或在没有请求的构建期间运行的组件中。",
  "versions": [
    {
      "version": "next@14.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "next@15.0.0-rc.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "next@13.5.6",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "headers() is a server-only function; it cannot be called in client components even in useEffect.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The function will still throw an invariant error, and the catch block will not provide valid header data.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "These functions run at build time without a request context, so headers() is not available.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Move the headers() call into an async Server Component or API route where the request context is available.",
      "success_rate": 0.9,
      "how": "Move the headers() call into an async Server Component or API route where the request context is available.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If you need headers in a utility function, pass them as a parameter from a Server Component.",
      "success_rate": 0.85,
      "how": "If you need headers in a utility function, pass them as a parameter from a Server Component.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the error occurs in a middleware, ensure headers() is called at the top level of the middleware function, not inside a nested callback or conditional.",
      "success_rate": 0.8,
      "how": "If the error occurs in a middleware, ensure headers() is called at the top level of the middleware function, not inside a nested callback or conditional.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "将 headers() 调用移入可用的请求上下文的异步服务器组件或 API 路由中。",
    "如果在实用程序函数中需要标头，请从服务器组件将它们作为参数传递。",
    "如果错误发生在中间件中，请确保 headers() 在中间件函数的顶层调用，而不是在嵌套的回调或条件语句中。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nextjs.org/docs/messages/invariant-headers-requestAsyncStorage",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}