Skip to content
Latchkey

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.

Prisma
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

  1. Add a dedicated generate step after npm ci in the workflow.
  2. Run it before build, test, or start.
  3. Do not rely only on postinstall when caching node_modules.
.github/workflows/ci.yml
- run: npm ci
- run: npx prisma generate
- run: npm test

Add a postinstall generate hook

Wire prisma generate into postinstall so a fresh install always produces the client.

package.json
{
  "scripts": {
    "postinstall": "prisma generate"
  }
}

How to prevent it

  • Run prisma generate as 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.

Related guides

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