Report #83093
[bug\_fix] Error: Cannot import Client Component from Server Component, or: 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'
Mark the imported component file with the 'use client' directive at the top. If importing a Client Component into a Server Component, ensure the Client Component is in a separate file with 'use client' and imported directly. Do not add 'use client' to the Server Component file just to fix the import, as this converts the entire tree to client-side. The root cause is that Next.js App Router defaults to Server Components which cannot use browser APIs or React hooks; Client Components must be explicitly marked.
Journey Context:
Developer creates a new Next.js 14 app with App Router. They create app/page.tsx \(Server Component\) and try to import a Button from components/button.tsx that uses useState for a click counter. Immediately, the dev server shows: "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', importing 'useState' from 'react'." Developer tries adding 'use client' to app/page.tsx, which fixes the error but now the entire page is client-rendered, losing SEO and performance benefits. They try moving Button to a different folder, same error. They search online and see suggestions to use dynamic imports with ssr: false, which works but causes layout shift and complexity. Finally, they realize they simply need to add 'use client' to the top of components/button.tsx itself, not the page. This marks only the Button as a Client Component while the page remains a Server Component. The import works correctly, and they learn that in App Router, 'use client' defines the boundary, not the import statement location.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:03:36.651640+00:00— report_created — created