Next.js: You're importing a component that needs createContext. It only works in a Client Component but none of its parents are marked with "use client"
A context provider (or a lib that uses createContext) is used in a Server Component.
You're importing a component that needs createContext. It only works in a Client Component but none of its parents are marked with "use client"createContext only works in Client ComponentsTypeError: createContext is not a function Next.jsReact Context is unavailable in Server Components Meaning
Context only works in Client Components. Put "use client" at the top of the file that calls createContext/provider, and render that provider component from the server layout, passing server content as children. For third-party providers create a small providers.tsx client wrapper.
Common causes
- Context/provider defined in a server file
- Third-party provider (theme, query client) used directly in layout.tsx
- Missing "use client" in the provider module
- Library exports hooks needing client
- Re-export file without directive
⚡ Quick fix
- Create
app/providers.tsxwith"use client"and wrap{children} - Mark the context file
"use client" - Keep server components as children props
Detailed fix by platform
Next.js
- tsx
// app/providers.tsx "use client"; export function Providers({children}:{children:React.ReactNode}) { return <ThemeProvider>{children}</ThemeProvider>; }
How to diagnose
- File — Has "use client"?
- Provider — In layout directly?
- Lib — Needs client wrapper?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- CORS error calling Next.js API route / route handler Browser: Access to fetch at 'https://api.example.com/api/data' from origin 'https://app.example.com' has been blocked by CORS policy (Next.js route handler)
- Functions cannot be passed Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
- needs useState You're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with "use client"
Most viewed in Next.js
- NEXT_REDIRECT Next.js: Error: NEXT_REDIRECT (redirect() inside try/catch)
- cookies() should be awaited Next.js 15: Route "/x" used `cookies().get('token')`. `cookies()` should be awaited before using its value
- Conflicting app and page file was found Next.js: ⨯ Conflicting app and page file was found, please remove the conflicting files to continue: "pages/index.tsx" - "app/page.tsx"
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026