Skip to content
Latchkey

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.

NestJS
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

  1. Add a prisma generate step after install.
  2. Run it before nest build and before the test suite.
  3. Confirm the schema path is correct for the generate command.
.github/workflows/ci.yml
- run: npm ci
- run: npx prisma generate
- run: npm run build

Generate on postinstall

A postinstall script regenerates the client automatically after any install.

package.json
"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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →