Skip to content
Skip to content
Essay8 min read

Why Your AI-Generated Next.js App Works Locally but Dies on Vercel

Four hours of vibe coding, perfect local dev, then a Vercel build fails on a case-sensitive import the model "fixed" once. Here is how to catch it before the PR.

Critique

You vibe-coded for four hours. The dashboard renders. Auth works. The AI agent closed twelve todos. You push, open the PR, and Vercel replies with a red X: Module not found: Can't resolve './component'. You stare at the file list. The component exists — as Component.tsx. Somewhere in the diff, the model renamed the import to lowercase in one file and left the filename alone. macOS never complained. Linux did.

Direct answer

Local Next.js dev and Vercel production builds are not the same environment. next dev is forgiving, case-insensitive on macOS, and lazy about type-checking. Vercel runs next build on Linux with strict module resolution. AI coding agents amplify the gap because they edit import paths confidently and inconsistently. Run next build locally, verify env vars per Vercel environment, and scan for case drift before you push.

Development mode optimizes for speed, not parity. Hot reload, loose transpilation, and skipped routes mean you can ship a green localhost and still fail the production compiler. TypeScript errors that never block dev can hard-fail next build. Dynamic imports the model added without ssr: false can explode during static analysis. Tree-shaking exposes dead imports the dev server never evaluated.

Local dev vs Vercel build
Same repo, different rules.
The failure is rarely mysterious once you treat Vercel as the source of truth, not your laptop.
Check`next dev`Vercel `next build`
FilesystemOften case-insensitive (macOS default)Linux — case-sensitive module resolution
TypeScriptErrors may not block the dev serverCompile errors fail the deployment
Env varsReads .env.local on your machineUses Vercel project env per environment
AI import editsWrong casing may still resolveModule not found — build stops
Run this before every AI-heavy push
  1. 1
    Does production build pass locally?
    Run npm run build or pnpm build. If it fails here, it will fail on Vercel. Fix before opening the PR.
  2. 2
    Are import paths consistent with filenames?
    Search for renamed components. On macOS, run git config core.ignorecase false in the repo or use a Linux CI job to catch casing regressions early.
  3. 3
    Are Preview env vars set?
    Open Vercel → Settings → Environment Variables. Confirm Preview has every key your feature reads, not just Production.
  4. 4
    Did TypeScript run in strict mode?
    Run tsc --noEmit if your build script skips full type-check. AI-generated props and any casts love to hide here.

Commands that mirror Vercel

# Match what Vercel runs
pnpm install --frozen-lockfile
pnpm build

# Optional: type-check explicitly
pnpm exec tsc --noEmit

Manual rituals help, but the durable fix is verifying the PR in an environment that behaves like Vercel — not re-running the same local dev command and hoping. Our guide on Vercel build failures on pull requests walks through running builds in ephemeral sandboxes, catching TypeScript and circular-import errors on the branch, and treating Preview deploys as a merge gate rather than a surprise. Read it at /vercel-build-failed-on-pull-request if you want the full playbook.

Critique can run sandbox verification against your PR: install, build, and test in an isolated Linux environment so case sensitivity and compile failures surface as review evidence before your reviewer ever opens the diff. That is especially useful when the author is an agent that does not remember yesterday's import path.

4h
Typical vibe-coding session before the first Vercel red X.
1
Wrong-cased import is enough to fail the whole deployment.
10m
Pre-push ritual — cheaper than a revert after merge.

Stop shipping green localhost, red Vercel
Connect Critique to GitHub and verify your next AI-generated PR builds in a Linux sandbox before it merges.
Independent reviewVerified repairReal repositoriesBuilt for developersLoved by agents