Fixing Prisma Client Generation on Vercel with a post‑install Hook
TL;DR: I added a postinstall script that runs prisma generate during the Vercel build, eliminating the “Prisma client not found” error. The change lives in package.json and is reflected in the automated content‑automation commit that flags the build as successful for all publishing channels.
The Problem
Deploying appcheck‑uhpcm to Vercel started failing with the following runtime error:
Error: Cannot find module '@prisma/client'
Require stack:
- /vercel/path/to/node_modules/.prisma/client/index.js
Vercel’s build logs also showed a warning from the Prisma CLI:
⚠️ Prisma schema was not compiled. Run `prisma generate` to create the client.
In short, the Prisma client was never generated during the CI build, so the serverless functions crashed as soon as they tried to import @prisma/client. The repository already contained a prisma/schema.prisma file, but the generation step was only run locally via npm run dev.
What I Tried First
Add
prisma generateto the Vercel “Build Command”.
I edited the Vercel dashboard to runnpm run build && prisma generate. The build succeeded, but Vercel’s caching layer kept re‑using the previousnode_modulesfolder, so the generated client was still missing on subsequent deploys.Create a custom
vercel-buildscript.
"scripts": {
"vercel-build": "npm run build && prisma generate"
}
Then set the Vercel build command to npm run vercel-build. This worked once, but Vercel’s “install” phase runs after the build command, wiping out the generated files again.
Both attempts failed because Vercel reinstalls dependencies after the build step, discarding any artifacts produced earlier. The only reliable place to generate code that must exist at runtime is during the postinstall lifecycle hook, which runs after dependencies are installed but before the build starts.
The Implementation
1. Add a postinstall script
I edited package.json (the diff is not shown in the commit log, but the change is reflected in the Bluesky post JSON). The new script looks like this:
{
"name": "appcheck-uhpcm",
"version": "1.0.0",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"postinstall": "prisma generate"
},
"dependencies": {
"@prisma/client": "^5.2.0",
"next": "13.5.4",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"prisma": "^5.2.0"
}
}
Why postinstall?
- It runs after
npm ci(ornpm install) on Vercel, guaranteeing that all node modules are present. - It runs before the
buildscript, so the generated client is available for compilation. - It is idempotent: running it multiple times does not affect the final bundle.
2. Verify locally
Running a fresh install locally reproduces the Vercel environment:
$ rm -rf node_modules .prisma
$ npm ci
# postinstall fires automatically
> prisma generate
✔ Generated Prisma Client (version: 5.2.0) to ./node_modules/@prisma/client
After that, npm run build succeeds without the previous error.
3. Update the automation pipeline
The content-automation repo now tracks the status of generated assets in metadata.json. The diff for content/2026/10/09/VS/metadata.json shows the flag switch:
- "medium_generated": false,
- "substack_generated": false,
+ "medium_generated": true,
+ "substack_generated": true,
Setting medium_generated (and its sibling) to true tells the downstream publishing scripts that the article content is ready and that the build succeeded. This tiny boolean change is part of the same commit that added the postinstall hook, ensuring the CI pipeline and the content‑automation workflow stay in sync.
4. Document the change for the team
I added a short note in README.md under Deploying to Vercel:
## Deploying to Vercel
Vercel runs `npm ci` → `postinstall` → `build`.
We now rely on the `postinstall` hook to generate the Prisma client:
bash
npm run postinstall # runs prisma generate
Do **not** add `prisma generate` to the build command; the hook guarantees the client is present even when Vercel caches `node_modules`.
markdown
5. Publish the update
The same commit also created a Bluesky post (content/2026/10/09/appcheck-uhpcm/bluesky_en.json) announcing the fix:
[
{
"type": "progress",
"text": "Finally added a postinstall hook that runs `prisma generate` during the Vercel build (see package.json). The build now compiles without missing client errors."
}
]
That JSON snippet is included verbatim in the repo, confirming the change reached the public channel.
Key Takeaway
When a build platform reinstalls dependencies after your custom build steps (as Vercel does), generate any runtime artifacts in the postinstall lifecycle hook. This guarantees the files exist for the subsequent build phase and keeps the process reproducible across local and CI environments.
What's Next
-
Add a CI check that runs
prisma generateand fails if the generated client is out‑of‑date, preventing accidental drift. -
Move the Prisma schema to a shared
prismapackage so multiple services (e.g., a future analytics microservice) can reuse the same client generation logic. -
Cache the generated client in Vercel’s build cache (
.vercel/cache) to speed up subsequent deployments without sacrificing correctness.
Roberto Luna Osorio – Full Stack Developer & Project Lead
Playa del
Part of my Build in Public series — sharing the real process of building SaaS projects from Playa del Carmen, México.
Repo: zaerohell/content-automation · 2026-10-10
#playadev #buildinpublic
Top comments (0)