Fix guides · Cursor, Claude Code, Bolt ·
Fix "@prisma/client did not initialize yet"
@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
Prisma builds a custom database client from your schema.prisma file using the `prisma generate` command. This error means your code imported `@prisma/client`, but the generated client isn't where that import expects it: generate never ran, it ran before the latest install or deploy, or it wrote the client to a custom folder. Usually the fix is to run `npx prisma generate`, point your imports at the actual output folder, and add `prisma generate` to your `postinstall` or build script so deploys always run it.
Common causes – and how to tell which one you have
1. prisma generate never ran
How to tell: Happens on a fresh clone, a new machine, or right after deleting node_modules. Running `npx prisma generate` locally makes the error go away.
Fix: Run `npx prisma generate` from the project root, then fully restart your dev server. Add `"postinstall": "prisma generate"` to package.json scripts so every install regenerates the client.
2. Deploy build skips generation (Vercel cache)
How to tell: Works locally but fails on Vercel or another host, often after a redeploy. The build log has no 'Generated Prisma Client' line.
Fix: Hosts like Vercel cache dependencies, so automatic generation may not run. Add `prisma generate` to your `postinstall` script or build script (e.g. `"build": "prisma generate && next build"`), then redeploy.
3. Client generated to a custom output folder
How to tell: The `generator client` block in schema.prisma has an `output` line (e.g. `output = "../generated/prisma"`), but your code still says `import { PrismaClient } from "@prisma/client"`. Newer `prisma init` projects and the newer `prisma-client` generator set this up.
Fix: Change your imports to the generated folder instead of `@prisma/client`. For the newer `prisma-client` generator, import from the `client` file inside the output folder (e.g. `./generated/prisma/client`). Use a relative path that matches your folders.
4. Schema changed but client not regenerated
How to tell: You or the AI recently edited schema.prisma or ran a migration, and the error (or missing model/field errors) started then.
Fix: Run `npx prisma migrate dev` (or `npx prisma db push` for prototypes), then run `npx prisma generate`. Newer Prisma versions don't always run generate automatically after these commands. Restart the dev server.
5. Prisma can't find the schema
How to tell: `prisma generate` errors with something like 'Could not find Prisma Schema', or your schema isn't at `prisma/schema.prisma`. Common in monorepos.
Fix: Run generate with `--schema path/to/schema.prisma`, or set the schema location in your Prisma config (prisma.config.ts or the `prisma` field in package.json, depending on version). Run it from the folder whose package.json uses Prisma.
6. Install scripts disabled or monorepo mismatch
How to tell: Your package manager runs with `--ignore-scripts`, or you use pnpm workspaces/monorepos and `@prisma/client` resolves from a different node_modules than the generated client.
Fix: Run `prisma generate` explicitly in the build step of the app that uses it. Consider a custom `output` path inside that app, imported directly, so resolution doesn't depend on hoisting.
How to fix it
- Open prisma/schema.prisma and look at the `generator client` block. Note the `provider` and whether there's an `output` line.
- In a terminal at the project root, run `npx prisma generate`. Read the output to see where it says the client was generated.
- If the client was generated to a custom folder, change every `import { PrismaClient } from "@prisma/client"` to import from that folder instead (for the `prisma-client` generator, the `client` file inside it). Use a relative path that matches your project.
- Stop the dev server completely and start it again so it picks up the new generated code.
- In package.json scripts, add `"postinstall": "prisma generate"`, or prefix your build script, e.g. `"build": "prisma generate && next build"`.
- If you changed the schema, run `npx prisma migrate dev` (or `npx prisma db push`), then `npx prisma generate` again.
- Commit, redeploy, and check the deploy build log for 'Generated Prisma Client'. Then load a page that queries the database.
Using Lovable, Bolt or v0?
In Bolt, ask: "Run `npx prisma generate`, check whether schema.prisma's generator has an `output` path, make all PrismaClient imports point to that generated location, add a postinstall script that runs prisma generate, then restart the dev server." Bolt has a terminal, so check its output for 'Generated Prisma Client'. If you deploy to Vercel, open the latest deployment's build logs and confirm that line appears; if not, add `prisma generate` to the build script and redeploy. Also check that your DATABASE_URL environment variable is set in the host's project settings, since that's often the next error.
Using Cursor, Claude Code or Windsurf?
Ask the agent to read the `generator client` block in schema.prisma and list every file importing PrismaClient, then confirm the imports match the generator's output location before changing anything. Have it run `npx prisma generate` and show you the output path it printed. To verify, have it restart the dev server, run the production build (e.g. `npm run build`), and hit a route that queries the database. Tell it to also add `prisma generate` to `postinstall` or the build script so deploys don't regress.
The “fix” to avoid
Agents often edit or copy files inside node_modules/.prisma, commit node_modules or generated files to git, or downgrade Prisma until the error changes. These break on the next install or deploy and hide the real problem, which is missing generation or a wrong import path. Also refuse `prisma migrate reset` or `db push --force-reset` here: they don't fix this error and can wipe your database data.
Copy-paste fix prompt for your AI coding tool
Paste this into Cursor, Claude Code, Lovable or Bolt:
My app fails with: "@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again." Check these causes in order: 1) Read the `generator client` block in schema.prisma. If it has an `output` path, find every file importing from "@prisma/client" and change it to import from the generated output (for the `prisma-client` generator, the `client` file inside that folder). 2) Run `npx prisma generate` and tell me the output path it reports. If it can't find the schema, fix the schema path or config. 3) Add `"postinstall": "prisma generate"` to package.json, or put `prisma generate &&` before the build command. Don't edit node_modules, commit generated files, downgrade Prisma, or reset the database. Verify by restarting the dev server, running the production build, and querying the database from a real route.
Questions people ask
Why does it work locally but fail on Vercel?
Vercel caches dependencies between builds, so Prisma's automatic generation may not run and the deployed client is missing or outdated. Add `prisma generate` to a `postinstall` script or your build command, then redeploy.
Do I need to run prisma generate after every schema change?
Yes. The client is built from your schema, so it must be regenerated whenever the schema changes. Newer Prisma versions don't always do this automatically after migrations, so run `npx prisma generate` yourself.
Should I commit the generated Prisma Client to git?
Usually no. Ignore the generated folder in .gitignore and generate it during install or build, so it always matches your schema and the deploy platform.