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:

  1. Install prisma as a dev dependency by running the following command in your terminal:
npm i -D prisma
  1. Next, open your package.json file and locate the scripts section. Add the following line to the scripts:
"postinstall": "prisma generate"

Your package.json should look something like this:

{
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "postinstall": "prisma generate"
  },
  "dependencies": {
    // dependencies...
  },
  "devDependencies": {
    // dev dependencies...
    "prisma": "^2.24.1"
  }
}
  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!