Prisma "@prisma/client did not initialize yet. Please run prisma generate" in CI
The @prisma/client package installed, but its generated code was never produced on this runner. prisma generate writes the actual client into node_modules; without that step the imported client throws at first use.
What this error means
Your app or tests throw "@prisma/client did not initialize yet. Please run 'prisma generate' and try to import it again." even though the dependency is in package.json.
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
at new PrismaClient (/app/node_modules/.prisma/client/default.js:43:11)Common causes
No generate step ran after install
CI ran npm ci but never ran prisma generate, so the client stub in node_modules was never replaced with generated code.
A cached node_modules skipped postinstall
When node_modules is restored from cache, npm ci does not run the prisma generate postinstall again, leaving a stale or empty client.
How to fix it
Run prisma generate explicitly after install
- Add a dedicated generate step after
npm ciin the workflow. - Run it before build, test, or start.
- Do not rely only on postinstall when caching node_modules.
- run: npm ci
- run: npx prisma generate
- run: npm testAdd a postinstall generate hook
Wire prisma generate into postinstall so a fresh install always produces the client.
{
"scripts": {
"postinstall": "prisma generate"
}
}How to prevent it
- Run
prisma generateas an explicit CI step, not only via postinstall. - If you cache node_modules, still run generate after the restore.
- Keep the generate step before any build or test that imports the client.