Next.js: You're importing a component that needs "server-only". That only works in a Server Component
A Client Component (or a file it imports) pulls in server-only code — database clients, secrets, next/headers or a module marked import "server-only".
Seen on:
Next.js
Meaning
Everything imported by a "use client" file is bundled for the browser. Server code must stay in Server Components, route handlers or server actions, and pass data down as props.
Common causes
- "use client" component importing a db/util module
- Shared barrel file (index.ts) mixing server and client exports
- Using next/headers or cookies in a client component
⚡ Quick fix
- Fetch data in a Server Component and pass props
- Move server logic into a server action
- Split barrel files into client-safe and server-only modules
Detailed fix by platform
TypeScript
- tsx
// lib/db.ts import "server-only"; // app/page.tsx (Server Component) const posts = await getPosts(); return <PostList posts={posts} />; // PostList can be "use client"
How to diagnose
- Import chain — Shown in the error trace
- Barrels — Mixed exports?
🔧 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
- async Client Component Error: async/await is not yet supported in Client Components, only Server Components.
- Can't resolve 'fs' Module not found: Can't resolve 'fs' (Next.js / webpack 5)
- cookies() should be awaited Next.js 15: Route "/x" used `cookies().get('token')`. `cookies()` should be awaited before using its value
Other ways to find it
🧠 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026