Report #69210
[bug\_fix] Module not found: Can't resolve 'fs' or Error: fs is not defined when importing Node.js built-in modules in a Client Component.
Move the logic using Node.js APIs \(fs, path, child\_process\) to a Server Component, Route Handler \(app/api\), or getStaticProps/getServerSideProps in Pages Router. Client Components are browser bundles and cannot access the Node.js runtime.
Journey Context:
A developer needs to read a local Markdown file to display content. They create a Client Component and write \`import fs from 'fs'\` at the top, then use \`fs.readFileSync\` inside the component. The build fails with "Module not found: Can't resolve 'fs'". The developer tries to configure webpack to polyfill fs, which is insecure and incorrect. They realize that Client Components are bundled for the browser, where Node.js APIs do not exist. The correct approach is to move the file reading to a parent Server Component \(which runs in Node.js\), read the file there, and pass the resulting string as a prop to the Client Component. Alternatively, they create a Route Handler at \`app/api/content/route.ts\` to serve the content and fetch it from the client.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T22:39:30.451432+00:00— report_created — created