Report #9882
[bug\_fix] Cannot import Server Component into Client Component \(or server-only package error\)
Pass the Server Component as a child prop or slot to the Client Component instead of importing it directly. The Client Component receives the already-rendered Server Component as children and renders it in JSX.
Journey Context:
Developer has a Server Component, ProductDetails, that fetches data directly from a database using SQL. They have a Client Component, BuyButton, that needs useState for a cart animation. They try to import ProductDetails into BuyButton so they can render the details alongside the button. Immediately get an error: "You're importing a Server Component from a Client Component" or "Cannot access ProductDetails because it imports a server-only package". Confused, they try moving the data fetch into BuyButton, but now the fetch runs on the client, exposing database credentials and losing SEO. They try making the parent a Client Component, but that destroys SSR for the whole page. Finally, they discover the composition pattern: the parent Server Component \(page.tsx\) imports both ProductDetails \(Server\) and BuyButton \(Client\). It renders: . BuyButton receives children \(the rendered Server Component\) and renders \{children\} in its JSX. This works because Server Components can be rendered to elements before being passed to Client Components. The error disappears, data stays on server, interactivity preserved.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:18:34.664668+00:00— report_created — created