Common Next.js errorsModule not found: Can't resolve 'fs'
Module not found: Can't resolve 'fs' (or 'path', 'crypto', 'net') means code that only works on the server ended up in the browser bundle. The browser has no file system, so the build can't include it.
Why it happens
A file marked 'use client', or imported by one, imports a server-only helper: a database client, a file reader, or a package that uses Node.js built-ins.
How to fix it
Keep the server work in a Server Component, a Route Handler or a Server Action, and pass only the result to the client. Mark server-only files so a wrong import fails loudly and early:
import 'server-only'
import { readFile } from 'node:fs/promises'
export async function loadTemplate(name: string) {
return readFile(`./templates/${name}.html`, 'utf8')
}
Install it with npm install server-only. If a third-party package pulls in Node.js built-ins, check whether it has a browser build, or only import it on the server.