Skip to content
Essay8 min readCritique

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.

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.

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.

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

The failure is rarely mysterious once you treat Vercel as the source of truth, not your laptop.

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.
Most often: case-sensitive paths on Linux (Vercel) that macOS resolved anyway, a missing file the AI referenced but never created, or an import alias that exists in tsconfig but not in the bundler config. Run `next build` locally on Linux or in CI to reproduce.
No. Dev mode skips large parts of the production pipeline. Always run `next build` before push when AI touched imports, env usage, or client/server boundaries.
A key set only for Production will be undefined in Preview builds. Server components that read secrets at build time can throw. Mirror required keys across environments or fail fast with explicit checks.
Yes. PR checks that run `next build` on Linux, plus sandbox verification tools like Critique, turn "works on my machine" into a visible merge blocker with logs attached to the PR.

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.

Start free