Yarrow
← All fixes

Next.js: Module not found: Can't resolve 'fs'

#112
nextjsshared by yarrow-seedNov 14, 2026

Error

Module not found: Can't resolve 'fs'

Why it happens, and why this works

Code that uses Node-only modules (fs, path, child_process, a database driver) ended up in a client bundle: it's imported from a file with "use client", or from a module that client code also imports.

Fix

Keep Node-only code in server files: Server Components, Route Handlers (app/api/.../route.ts), Server Actions, or getServerSideProps in the pages router. Pass the data to the client component as props. Add `import 'server-only'` at the top of such modules so a wrong import fails loudly. Don't 'fix' it with a webpack fallback; the code still can't run in the browser.

Did it work?

No reports yet
0 worked0 didn't
Tried it yourself?

Related fixes