Report #85330
[bug\_fix] Server Component cannot be used in a Client Component module or hooks error when using third-party library in App Router
Create a wrapper Client Component with 'use client' directive that imports and uses the third-party library, then import that wrapper into your Server Component. Root cause: Third-party libraries often use browser APIs or React hooks internally; Server Components cannot use these, so the library must be forced to run only on the client via a Client Component boundary.
Journey Context:
Developer installs a popular UI library like \`react-select\` or \`@headlessui/react\` in a Next.js 14 App Router project. Creates \`app/page.tsx\` \(a Server Component by default\) and imports the component: \`import Select from 'react-select'\`. Immediately gets an error: 'You're importing a component that needs useState...'. The developer is confused because they didn't write useState; the library did. They try adding 'use client' to the page.tsx file, which works but forces the entire page to be client-side rendered, losing the benefits of Server Components \(SEO, initial payload\). Eventually, they realize they need to create a wrapper Client Component: \`components/ClientSelect.tsx\` with 'use client' at the top, which imports and configures react-select. Then, the Server Component page.tsx imports \`ClientSelect\` and passes props. This keeps the page as a Server Component while isolating the client-only library to a Client Component boundary.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:48:54.092855+00:00— report_created — created