Next.js · build error
Module not found: Can't resolve 'fs'
./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
- Read files or call Node APIs in a Server Component, route handler or Server Action
- Pass the result to the client component as props
- Add import "server-only" to modules that must never reach the browser
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
Other Next.js errors
- useState / useEffect in a Server Component
- Event handlers cannot be passed to Client Component props
- Functions cannot be passed directly to Client Components
- Only plain objects can be passed to Client Components
- "use client" must be placed before other expressions
- export "metadata" from a "use client" page
$ 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.