Deploying Nextjs + Prisma using Vercel Output API

1. Set Prisma "binaryTargets"

When opting for using vercel output API, where the project is builded and deployed on separated services(e.g build on github action and deploy on vercel), you have to make sure to include the "binaryTargets" option in your schema.

generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-1.0.x"]
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")

The native target will automatically detect the OS and specifies the correct binary.

2. Replace the default vercel-build command

By default vercel perform the command "vercel-build" on every build. With prisma we have to extend this command to generate and migrate our schema.

Include the script bellow in your package.json

"scripts": {
  "vercel-build": "prisma generate && prisma migrate deploy && next build"


3. Create your github workflow following example

  • Generate Vercel token
  • Create a github action workflow

Reference: Github actions with Vercel.

That should be it. From here you can just trigger the github action by creating a pull request to your specified branch.

0 view