nextjs
server-components
ai_generated
true
Error: Invariant: headers() expects to have requestAsyncStorage
ID: nextjs/streaming-not-supported
90%Fix Rate
92%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 14 | active | — | — | — |
Root Cause
Calling headers()/cookies() outside of a request context — usually in a cached or generated page.
genericWorkarounds
-
93% success Ensure the function is called within a request context — mark the page as dynamic
export const dynamic = 'force-dynamic'
Sources: https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
-
85% success Pass headers as props from a parent Server Component that has request context
const h = headers(); return <Child headerValue={h.get('x-custom')} />
Dead Ends
Common approaches that don't work:
-
Wrapping in try/catch and returning empty headers
70% fail
Silently returns wrong data; features depending on headers break
-
Moving to middleware
60% fail
Middleware is for request routing, not data fetching
Error Chain
Frequently confused with: