Prisma works locally but fails on Vercel with a stale client or a missing prisma command
PrismaClientInitializationErrorShort answer
Vercel caches dependencies between deployments, so the generated Prisma Client can be out of date after a schema change. Add a postinstall script that runs prisma generate. If the build says prisma: command not found, move prisma from devDependencies into dependencies.
Fix it fast
1Find out which cause you have
Open the failed deployment's build log on Vercel and read the lines around the Prisma step. They say whether generate ran or the prisma command was missing.
grep -n -E "prisma" package.json2Match what you see, then jump to its fix
- 1
The app builds, then Prisma Client errors at runtime after you changed schema.prismaCached dependencies mean prisma generate never ranFix - 2
prisma: command not found in the build logprisma is a dev dependency, so the build cannot find itFix - 3
A preview deploy changed or broke the production schemaMigrations run on previews against the production databaseFix
- 1
What does the error look like?
PrismaClientInitializationErrorprisma: command not found
Cause 1 of 3
Cached dependencies mean prisma generate never ran
1Check
Prisma's Vercel guide says Vercel automatically caches dependencies on deployment, which can leave Prisma Client out of date because nothing regenerates it.
grep -n -E "postinstall|\"build\"" package.json2Fix
Add a postinstall script so the client is regenerated on every install. Committing the generated client is the other option the guide names.
{
"scripts": {
"postinstall": "prisma generate"
}
}3Verify
Redeploy and check the build log for the generate step, then open the page that used the database.
npx prisma generateConfirmed by prisma.io
Cause 2 of 3
prisma is a dev dependency, so the build cannot find it
1Check
Prisma's guide notes prisma is a dev dependency by default and so may be missing during Vercel builds.
grep -n -B2 -A2 "\"prisma\"" package.json2Fix
Move prisma into dependencies in package.json, then reinstall to refresh the lockfile.
{
"dependencies": {
"prisma": "^6.0.0"
}
}3Verify
The build log shows prisma generate finishing.
npm installConfirmed by prisma.io
Cause 3 of 3
Migrations run on previews against the production database
1Check
The guide says production and preview environments both use the DATABASE_URL set when the project was imported, so a migration in a pull request can change the production schema.
# Vercel dashboard: Project > Settings > Environment Variables, read DATABASE_URL scopes2Fix
Add a DATABASE_URL that applies only to the Preview environment and points at a second database.
# Vercel Environment Variables: add DATABASE_URL, scope Preview only, value = second database3Verify
A preview deployment reads and writes the second database only.
# Check the preview app's data against the second databaseConfirmed by prisma.io
How do I stop it coming back?
- Keep postinstall prisma generate in package.json from the first deploy.
- Give previews their own database through a Preview-only DATABASE_URL.
- Run migrations in a vercel-build script rather than by hand.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Databases
Prisma says it can't reach the database server, but the database is up
Please make sure your database server is running at `localhost`:`5432`.
P1001 is Prisma's catch-all for any failed connection, even a wrong password, so do not trust the label.
4 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fix