Common Next.js errorsRoute couldn't be rendered statically because it used cookies or headers
Dynamic server usage: Route /dashboard couldn't be rendered statically because it used `cookies` (or headers, or searchParams). Next.js tried to build the page once, ahead of time, and found it depends on the visitor's request.
Why it happens
Usually one of two things: the page really is per-visitor but nothing tells Next.js, or the call that reads cookies is inside a try/catch that swallows the signal Next.js uses to switch the page to dynamic rendering.
How to fix it
Don't catch that error. If you have a try/catch around the code, let Next.js's errors through with unstable_rethrow(err) at the top of the catch. Then, if the page is per-visitor, say so:
app/dashboard/page.tsx // Render on every request
export const dynamic = 'force-dynamic'
export default async function Dashboard() {
const user = await getUserFromCookies()
// ...
}
If the page should be static, move the cookie or header read into a smaller component, or into the client, so the rest of the page can still be built once.