A client-side file imported fs, which only exists in Node.js. Move the fs code into server-only code, such as getStaticProps, a Route Handler or a Server Component.
The browser bundle cannot include Node built-ins like fs, path or net. The error appears when a file that ends up in the client bundle imports one, directly or through a library.
- Move the file reading into server code and pass the result to the component as props.
- In the App Router, add
import "server-only"to modules that must never reach the browser; the build then points at the exact client import that pulls it in. - In the Pages Router, imports used only inside
getStaticPropsorgetServerSidePropsare removed from the client bundle. - As a last resort for a library with an optional
fscall, aliasfsto an empty module for the browser:turbopack.resolveAliasinnext.config.js(the default bundler in Next.js 16), orresolve.fallback = {fs: false }in a webpack config if you build with--webpack.
// lib/read-content.ts
import "server-only";
import { readFile } from "node:fs/promises";
export const readContent = (name: string) => readFile("content/" + name, "utf8");