NestJS + Prisma "@prisma/client did not initialize yet" in CI
The Prisma client is generated code that must be created by prisma generate after install. In CI a clean install does not run it automatically, so the NestJS PrismaService fails because the client is not initialized.
What this error means
App or test startup fails with "@prisma/client did not initialize yet. Please run \"prisma generate\" and try to import it again." from the PrismaService.
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/index.js:...)Common causes
prisma generate did not run in CI
The generated client lives in node_modules/.prisma and is not committed, so a clean install leaves it uninitialized until generate runs.
No postinstall hook to generate the client
Without a postinstall script or an explicit CI step, npm ci restores dependencies but never regenerates the client.
How to fix it
Run prisma generate before build and test
- Add a
prisma generatestep after install. - Run it before nest build and before the test suite.
- Confirm the schema path is correct for the generate command.
- run: npm ci
- run: npx prisma generate
- run: npm run buildGenerate on postinstall
A postinstall script regenerates the client automatically after any install.
"scripts": { "postinstall": "prisma generate" }How to prevent it
- Run prisma generate in CI after install, before build and tests.
- Add a postinstall script so the client is always regenerated.
- Do not commit the generated client; regenerate it in each environment.