Report #95045
[bug\_fix] Module not found: Can't resolve 'fs' \(or 'path', 'child\_process'\) in Client Component
Move the Node.js-specific code to a Server Component \(async function\) and pass the fetched data as props, or use dynamic import\(\) inside useEffect with ssr: false if client-side execution is absolutely required.
Journey Context:
Developer writes a utility function that uses fs.readFileSync or imports the 'fs' module to read local files. They import this utility into a Client Component \(a file with 'use client' or a component in the Pages Router\). When running next build or starting the dev server, Webpack throws 'Module not found: Can't resolve 'fs''. The developer is confused because the code works in a standalone Node.js script. They realize that Client Components are bundled for the browser environment, where Node.js built-in modules like 'fs', 'path', and 'child\_process' do not exist. The solution is to keep all file-system operations in Server Components \(which run on the server during SSR\), fetch the data there, and pass it as props to the Client Component. Alternatively, if the file must be read on the client \(rare\), they can use dynamic import\('fs'\) inside a useEffect with ssr: false, but this is usually the wrong approach.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:06:49.988015+00:00— report_created — created