Error AtlasError Documentation and Resolution

Next.js Dynamic Server Usage loses request context

DynamicServerError

Request APIs such as cookies and headers rely on the active request context. Calling them in detached asynchronous work can produce an uncaught DynamicServerError during generation.

DynamicServerErrorrendering
DynamicServerError
  • Request data is read inside a delayed callback.
  • A promise using request APIs is started but not awaited.
  1. Read and await request data while the server render still has request context, before entering a timer or detached callback; pass the resulting values into that callback.
  2. Await helper functions that call request APIs and inspect the stack for unawaited asynchronous branches.
  3. Distinguish an uncaught failure from Next.js internally detecting dynamic usage and opting a route into dynamic rendering. Fix the offending execution path, then rerun next build.
Next.js official documentation