Skip to content
Latchkey

Prisma "did not initialize yet" missing prisma generate in CI

Importing @prisma/client requires generated code that prisma generate produces. In CI the client package was installed but never generated (often because a cached node_modules skipped the postinstall), so the runtime throws.

What this error means

A migrate, seed, or test step fails with "@prisma/client did not initialize yet. Please run \"prisma generate\" and try to import it again." even though the package is installed.

prisma output
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
    at new PrismaClient (.../@prisma/client/...)

Common causes

A cached install skipped postinstall generation

When node_modules is restored from cache, the prisma generate postinstall hook does not run, so the generated client is absent or stale.

No explicit generate step before using the client

The pipeline installs dependencies and then imports the client without ever calling prisma generate.

How to fix it

Run prisma generate explicitly

Add a generate step after install and before any code that imports the client.

.github/workflows/ci.yml
- run: npm ci
- run: npx prisma generate
- run: npx prisma migrate deploy

Keep generate in postinstall and avoid stale cache

  1. Add "postinstall": "prisma generate" to package.json so fresh installs generate the client.
  2. Include the Prisma schema in the cache key so a schema change invalidates the cache.
  3. When in doubt, run prisma generate explicitly in CI regardless of caching.

How to prevent it

  • Always run prisma generate after install in CI.
  • Key dependency caches on the Prisma schema so client and schema stay in step.
  • Keep a postinstall generate hook for local and fresh installs.

Related guides

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