Report #17735
[bug\_fix] Module not found: Can't resolve 'fs' in Client Component
Move the import/usage to a Server Component, or use \`next/dynamic\` with \`ssr: false\` to load the library only on the client. Root cause: Client Components are bundled for the browser which lacks Node.js APIs; the build fails when webpack tries to resolve server-only modules.
Journey Context:
You install a markdown parser that uses \`fs\` to read files. You import it in a Client Component to render markdown. The dev server crashes with 'Module not found: Can't resolve fs'. You check node\_modules and see the library indeed imports 'fs'. You initially try to polyfill it in next.config.js, but that's wrong. You realize this code must run on the server. You move the import to a Server Component \(a parent or the same file made into an RSC\) and pass the parsed result as props. Alternatively, for a browser-only charting library, you use \`const Chart = dynamic\(\(\) => import\('chart-library'\), \{ ssr: false \}\)\`. The build succeeds because the server bundle no longer attempts to load Node-only code.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:15:33.652635+00:00— report_created — created