Report #100545
[bug\_fix] Next.js App Router: "This module cannot be imported from a Server Component module. It only works in a Client Component." when importing a component that uses useState, useEffect, event handlers, or browser APIs.
Add the "use client" directive as the very first line of the file that uses client-only React features. That file and every module it imports become part of the client bundle. Keep the directive as deep in the tree as possible—do not add it to the page unless the whole page needs interactivity.
Journey Context:
I extracted a Toggle switch with useState into app/ui/Toggle.tsx and imported it from a Server Component page. Next.js immediately threw an error because App Router components default to server-side rendering, where hooks and onClick do not exist. My first fix was adding "use client" to the page, which worked but de-optimized the entire route. The docs explain that the directive marks a client boundary, so I moved it to the top of Toggle.tsx only. The page stayed a Server Component and the toggle rendered as a client island.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T04:41:14.186501+00:00— report_created — created