Background
I had a Next.js project using Prisma and Postgres. Local npm run build looked fine, but Vercel deployments kept failing.
The goal looked simple: generate Prisma client and deploy. In reality, there were a few subtle traps.
What Broke
1) Prisma client output path mismatch
In schema.prisma, the generator output was customized:
generator client {
provider = "prisma-client-js"
output = "../generated/prisma"
}
But app code still imported from @prisma/client.
That means build/runtime could fail with errors like:
@prisma/client did not initialize yet. Please run "prisma generate"
Because generated client lived in generated/prisma, not default node_modules/@prisma/client.
2) Env expectation during prisma generate
schema.prisma used both:
DATABASE_URLDIRECT_URL
If one is missing in CI, prisma generate may fail during install/build.
3) Local success != production install success
Even when local dev install worked, production-like install (--omit=dev) could still fail if scripts/tools were not available in that mode.
Fixes That Worked
1) Import Prisma types/client from generated path
Use generated path consistently in app code:
import { PrismaClient } from "@/generated/prisma";
import type { Prisma } from "@/generated/prisma";
2) Run Prisma generate in both postinstall and build
{
"scripts": {
"postinstall": "DATABASE_URL=${DATABASE_URL:-postgresql://user:pass@localhost:5432/app} DIRECT_URL=${DIRECT_URL:-$DATABASE_URL} prisma generate",
"build": "DATABASE_URL=${DATABASE_URL:-postgresql://user:pass@localhost:5432/app} DIRECT_URL=${DIRECT_URL:-$DATABASE_URL} prisma generate && next build"
}
}
This made CI behavior more robust when some env vars were missing.
3) Validate with production-style local checks
Before pushing:
npm ci --omit=dev
npm run build
npx vercel build
This catches cloud-only failures much earlier.
Practical Checklist
When deploying Next.js + Prisma on Vercel:
- If
schema.prismahas customoutput, import Prisma from that generated location everywhere. - Ensure
prisma generateruns during CI (postinstalland/orbuild). - Confirm required env vars exist (
DATABASE_URL,DIRECT_URLif used). - Test with production-like install/build locally.
- Track deployment status per project if monorepo/multi-project webhooks are connected.
Final Learning
The biggest lesson: deployment issues were not about one magic Vercel setting. They came from small consistency gaps between Prisma generation path, imports, and CI environment assumptions.
Once those were aligned, Vercel deployment turned green.