Report #8345
[bug\_fix] Module not found: Can't resolve 'fs' in Client Component
Move the filesystem/database logic to a Server Component \(remove 'use client'\) or to a Route Handler \(API route\) and fetch from the client. Alternatively, use server-only package to enforce boundaries. Root cause: Client Components run in the browser where Node.js core modules like fs, path, and net do not exist.
Journey Context:
You create a utility db.ts that imports \{ sql \} from '@vercel/postgres' or simply uses fs.readFileSync to load local JSON. You import this into a Dashboard component that uses 'use client' because it has interactive charts. The build fails instantly with 'Module not found: Can't resolve fs'. You check node\_modules, it's there. You try webpack configure options to stub fs, which compiles but then crashes at runtime with 'fs is not defined' in the browser console. You realize App Router has Server Components by default. You move the data fetching out of the Client Component and into the parent Server Component \(page.tsx\), passing data as props to the Client Component. Or you create a Route Handler at app/api/data/route.ts and fetch\('/api/data'\) from the client using SWR or React Query.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:16:27.590217+00:00— report_created — created