Error AtlasError Documentation and Resolution

Next.js createContext used in a Server Component

createContext in a Server Component

Next.js detected React context creation inside a Server Component, which is unsupported because createContext only works in Client Components.

createContext in a Server Componentrendering
createContext in a Server Component
  • A component in the App Router creates React context without being marked as a Client Component.
  • Shared provider code was imported into a Server Component tree.
  • A file using createContext is missing the use client directive.
  1. Add use client at the top of the file that creates the context.
  2. Move the provider into a Client Component and render it from the server tree.
  3. Keep context-related code out of Server Components unless it is wrapped by a client boundary.
Next.js Docs: createContext in a Server Component
Next.js createContext in a Server Component: causes and fixes | Error Atlas