Next.js · build error

Module not found: Can't resolve 'fs'

what it looks like
./src/app/blog/page.tsx:2:1
Error: Module not found: Can't resolve 'fs'
> 2 | import fs from "fs";

What it means

Code that uses a Node.js API (fs, path, net, tls, child_process) is being bundled for the browser, where those modules don't exist.

Common causes

  • fs or path used inside a "use client" file
  • A client component imports a helper that reads files, or a Node-only package (database drivers, nodemailer)
  • A typo in an import path also gives Module not found, for your own files

How to fix it

  1. Read files or call Node APIs in a Server Component, route handler or Server Action
  2. Pass the result to the client component as props
  3. Add import "server-only" to modules that must never reach the browser

works with Next.js 16.4.3 · React 19.3last verified

prevent it · nextjs-app-router.mdc (free Cursor Rules Pack): Node-only and server-only modules stay out of client components.

Prompt for Cursor or Claude Code

Next.js can't resolve a Node built-in (like fs) in the browser bundle. Trace which "use client" file imports it, move the Node code into a Server Component or Server Action, and add import "server-only" to that module.

Not quite your error? Paste yours into the free VibeBoot Doctor or browse the Next.js error fixer.

next: skip the next one

Skip the setup. The VibeBoot SaaS Starter gives you auth, Stripe and a database already wired on Next.js 16.4.3, with AGENTS.md and .cursor/rules that keep your agent on the Next.js 16 conventions. $49, one-time.

14-day money-back guarantee · lifetime updates

$ fixed it? get the next one first

New fixes for what AI agents break, by email.

When we add a fix or a Cursor rule for a new Next.js, Auth.js, Prisma or Stripe break, it goes out in the VibeBoot newsletter. Free, occasional, unsubscribe in one click.

Subscribe free