Short answer
A file in the client bundle imports a Node.js module. Follow the import trace in the error to the "use client" file that pulls it in, then move the server code into a Server Component, a server action or a route handler, and pass only the data to the client. Add import "server-only" to server files so the next mistake fails clearly.
How server code ends up in the browser
01
A Client Component imports server code
“Once a file is marked with "use client", all of its imports and the components it directly renders are included in the client bundle.” Next.js, Server and Client Components
Everything a "use client" file imports goes to the browser. If it imports your database client or a file that reads from disk, the build tries to bundle fs. Move that call to the server side and pass the result down as props.
02
A shared helper file mixes both
“This means it's possible to accidentally import server-only code into the client.” Next.js, Server and Client Components
A utils file with both a formatting helper and a database call gets pulled into the client by the formatting helper. Split it into a client-safe file and a server file.
03
Mark server files with server-only
“To prevent accidental usage in Client Components, you can use the server-only package.” Next.js, Server and Client Components
Install the server-only package (npm install server-only) and import it at the top of server files. Importing one into the client then fails with a clear message pointing at the mistake.
import 'server-only'04
In the Pages Router, outside getServerSideProps
“The module you're trying to import uses Node.js specific modules, for example dns, outside of getStaticProps / getStaticPaths / getServerSideProps” Next.js, Module Not Found
Older Pages Router apps can use Node modules only inside getStaticProps, getStaticPaths or getServerSideProps, which Next.js removes from the browser bundle.
Checked against the vendor’s docs on : Next.js docs: Server and Client Components; Next.js docs: Module not found.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.See scope and start
Related: Vercel Module not found: Can’t resolve (casing) · Next.js window is not defined · Vercel npm run build exited with 1 · Next.js DynamicServerError