Report #66470
[bug\_fix] Error: \`cookies\` was called outside a request scope... or This function is not supported in Client Components
Move the logic calling \`cookies\(\)\` or \`headers\(\)\` to a Server Component \(async function\), or use a Route Handler \(API route\) if you need this data in the browser. Root cause: These APIs read from the incoming HTTP request object which only exists on the server during the request lifecycle.
Journey Context:
Developer is inside a Client Component \(marked with "use client"\) and attempts to read a session cookie: \`const token = cookies\(\).get\('session'\)\`. The compiler immediately throws: "Error: \`cookies\` was called outside a request scope". Developer tries \`await cookies\(\)\` thinking it's an async timing issue, but gets the same error. They check the Next.js docs and see the note that these are Server-only APIs. The fix involves lifting the data requirement to a parent Server Component. For example, in \`page.tsx\` \(which can be async\), they call \`const cookieStore = cookies\(\)\`, extract the value, and pass it as a prop to the Client Component. Alternatively, they fetch the cookie via an API route from the client.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:02:50.931984+00:00— report_created — created