How to Fix the prisma/client did not initialize yet
Error on Vercel
If you’re building an app with Next.js and Prisma and encounter the deployment error Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again
when deploying it on Vercel, don’t worry. There’s a simple solution to this problem.
The error occurs because the database is already initialized in your local development environment, but it needs to be properly generated and imported on the Vercel deployment.
To fix this, follow these steps:
- Install
prisma
as a dev dependency by running the following command in your terminal:
1 | npm i -D prisma |
- Next, open your
package.json
file and locate thescripts
section. Add the following line to the scripts:
1 | "postinstall": "prisma generate" |
Your package.json
should look something like this:
1 | { |
- Save the changes to the
package.json
file.
By adding the postinstall
script, you ensure that prisma generate
is automatically executed after the installation of dependencies when deploying on Vercel. This will generate the necessary Prisma artifacts and resolve the prisma/client did not initialize yet
error.
That’s it! Your app should now deploy successfully on Vercel without encountering the aforementioned error. Happy coding!
tags: [“error handling”, “Next.js”, “Prisma”, “Vercel”, “deployment”]