Build & Deploy
Bundlers, lockfiles, monorepos and the gap between localhost and production.
12 articles
ERR_REQUIRE_ESM on Vercel but not locally: the Next.js 16.2 monorepo bug
Your Next.js build passes and the Vercel deploy 500s with ERR_REQUIRE_ESM. Here is the missing .next/package.json that causes it, and three workarounds that hold.
JavaScript Heap Out of Memory on next build: Find the Real Cause
Raising --max-old-space-size hides the problem instead of fixing it. Three different build phases can exhaust the heap, and the last log line tells you which one you have.
Turbopack 'Cannot Find Module' With Pino and Dynamic requires
Next.js 16 made Turbopack the default bundler and packages that resolve module paths at runtime started breaking. Here is the mechanism and the correct fix, not just the flag.
NEXT_PUBLIC_ Vars Are Baked at Build Time: Why One Docker Image Can't Serve Staging and Prod
Your prod container still points at the staging API because NEXT_PUBLIC_ vars are string-replaced into the client bundle during next build, not read at container start. The two fixes that actually work.
Next.js 'Found multiple lockfiles': a silent monorepo footgun, not just noise
Next.js picks your workspace root by walking up for a lockfile. A stray one in a Docker layer or template silently changes which files ship. Pin the root explicitly.
Next.js 16.0.1 Fails next build on /_not-found: An Open Regression
Next.js 16.0.1 can break next build while prerendering the not-found page, even though next dev works. Here is how to confirm it, pin safely, and gate CI.
React.lazy Infinitely Remounts in Turbopack Dev: It Is Not Your Zustand Store
A React.lazy plus Suspense subtree with many useSyncExternalStore selectors mounts, unmounts and remounts forever in next dev. Why it is a Turbopack dev bug, and two clean workarounds.
useSearchParams() Should Be Wrapped in a Suspense Boundary: The Error Only Your Build Sees
Why useSearchParams() passes in next dev and kills your CI build, what the CSR bailout actually does, and the Suspense split that keeps the rest of the page static.
Vite '504 Outdated Optimize Dep' Explained: The Dependency Cache Race You Cannot Fully Avoid
Vite's 504 Outdated Optimize Dep is a version-hash cache race in dependency pre-bundling, not a network error. Here is the unstick, the optimizeDeps.include fix, and its limits.
moduleResolution 'NodeNext' Breaks Next.js Type Imports: Use 'bundler'
Setting moduleResolution to nodenext makes TypeScript report 'Cannot find module next/navigation'. Here is why NodeNext is too strict for Next.js and the tsconfig to use instead.
Next.js Hydration Mismatches That Are Not Your Fault: Turbopack and Edge Causes
Every hydration article blames Date.now() and browser extensions. When the mismatch is a color-scheme attribute or a path that resolves differently on Vercel Edge, that advice is useless.
serverExternalPackages Silently Fails Under pnpm and Turbopack
The same Next.js config that externalizes a package under npm gets bundled anyway under pnpm and Turbopack. Here is why, and the workarounds that actually hold.