nextjs server-components ai_generated true

Error: Invariant: headers() expects to have requestAsyncStorage

ID: nextjs/streaming-not-supported

Also available as: JSON · Markdown
90%Fix Rate
92%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
14 active

Root Cause

Calling headers()/cookies() outside of a request context — usually in a cached or generated page.

generic

Workarounds

  1. 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

  2. 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:

  1. Wrapping in try/catch and returning empty headers 70% fail

    Silently returns wrong data; features depending on headers break

  2. Moving to middleware 60% fail

    Middleware is for request routing, not data fetching

Error Chain

Frequently confused with: