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.
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.
- run: npm ci
- run: npx prisma generate
- run: npx prisma migrate deployKeep generate in postinstall and avoid stale cache
- Add
"postinstall": "prisma generate"to package.json so fresh installs generate the client. - Include the Prisma schema in the cache key so a schema change invalidates the cache.
- When in doubt, run
prisma generateexplicitly in CI regardless of caching.
How to prevent it
- Always run
prisma generateafter install in CI. - Key dependency caches on the Prisma schema so client and schema stay in step.
- Keep a
postinstallgenerate hook for local and fresh installs.