{"id":"c17ab3d0-17b2-42f5-ad3b-539da661853f","slug":"nextjs-you-re-importing-a-module-that-5ce1","url":"https://api.modalhub.ai/r/nextjs-you-re-importing-a-module-that-5ce1","urls":{"html":"https://api.modalhub.ai/r/nextjs-you-re-importing-a-module-that-5ce1","md":"https://api.modalhub.ai/r/nextjs-you-re-importing-a-module-that-5ce1.md","json":"https://api.modalhub.ai/r/nextjs-you-re-importing-a-module-that-5ce1.json","history":"https://api.modalhub.ai/r/nextjs-you-re-importing-a-module-that-5ce1/history"},"symptom":"You're importing a module that depends on `useState` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the `\"use client\"` directive.","command":"next build","exit_code":1,"tool":"nextjs","version":"16.2.0","os":null,"date":"2026-10-28","cause":"App Router files are Server Components by default and render without client state or effects, so the compiler rejects imports of client-only React APIs","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"+// app/counter.tsx: only the interactive part becomes a Client Component\n+'use client';\n+import { useState } from 'react';\n+export default function Counter() {\n+  const [n, setN] = useState(0);\n+  return <button onClick={() => setN(n + 1)}>{n}</button>;\n+}\n// page.tsx stays a Server Component: import Counter and render <Counter />"},"repro":"none","check":"next build","notes":"16.1 and older: \"You're importing a component that needs `useState`. This React hook only works in a client component.\" Same for useEffect, useRef, useReducer, createContext. A third-party component without the directive: re-export it from your own 'use client' file.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[]},"arms":[{"range":"16.2","status":"works"}],"dead_ends":[{"attempt":"add 'use client' below the imports","why":"the directive must be the first statement; Next fails with: The \"use client\" directive must be placed before other expressions","reports":1},{"attempt":"put 'use client' on page.tsx or the root layout","why":"the whole subtree becomes client code, and a page that exports metadata then fails: You are attempting to export \"metadata\" from a component marked with \"use client\"","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-10-28T18:26:45.577981Z","updated_at":"2026-10-28T18:26:45.577981Z","last_confirmed_at":null,"ledger":{"first_seq":61,"last_seq":61,"head_hash":"48a854b263b59b9a0c46e07f2aa70b22f15bee6c90e3336b3b1b19f08e7f966e"}}
