Issues implementing CI/CD preview environment with Vercel

I’ve been following these guides for implementing a preview environment with Neon branches and Vercel previews.

However, when I try to use Prisma I encounter this error.

The error in Vercel logs is as follows.
…sl-1.0.x\"]\n}\n\nThe following locations have been searched:\n /var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/.prisma/client\n /var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client\n /home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client\n /tmp/prisma-engines","reason":{"errorType":"PrismaClientInitializationError","errorMessage":"Prisma Client could not locate the Query Engine for runtime \"rhel-openssl-1.0.x\".\n\nThis happened because Prisma Client was generated for \"debian-openssl-1.1.x\", but the actual deployment required \"rhel-openssl-1.0.x\".\nAdd \"rhel-openssl-1.0.x\" to `binaryTargets` in the \"schema.prisma\" file and run `prisma generate` after saving it:\n\ngenerator client {\n provider = \"prisma-client-js\"\n binaryTargets = [\"native\", \"rhel-openssl-1.0.x\"]\n}\n\nThe following locations have been searched:\n /var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/.prisma/client\n /var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client\n /home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client\n /tmp/prisma-engines","name":"PrismaClientInitializationError","clientVersion":"5.4.2","stack":["PrismaClientInitializationError: Prisma Client could not locate the Query Engine for runtime \"rhel-openssl-1.0.x\".","","This happened because Prisma Client was generated for \"debian-openssl-1.1.x\", but the actual deployment required \"rhel-openssl-1.0.x\".","Add \"rhel-openssl-1.0.x\" to `binaryTargets` in the \"schema.prisma\" file and run `prisma generate` after saving it:","","generator client {"," provider = \"prisma-client-js\""," binaryTargets = [\"native\", \"rhel-openssl-1.0.x\"]","}","","The following locations have been searched:"," /var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/.prisma/client"," /var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client"," /home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client"," /tmp/prisma-engines"," at Ca (/var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client/runtime/library.js:65:776)"," at async fn.loadLibrary (/var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client/runtime/library.js:112:9777)"," at async mr.loadEngine (/var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client/runtime/library.js:114:447)"," at async mr.instantiateLibrary (/var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client/runtime/library.js:113:1762)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: PrismaClientInitializationError: Prisma Client could not locate the Query Engine for runtime \"rhel-openssl-1.0.x\".","","This happened because Prisma Client was generated for \"debian-openssl-1.1.x\", but the actual deployment required \"rhel-openssl-1.0.x\".","Add \"rhel-openssl-1.0.x\" to `binaryTargets` in the \"schema.prisma\" file and run `prisma generate` after saving it:","","generator client {"," provider = \"prisma-client-js\""," binaryTargets = [\"native\", \"rhel-openssl-1.0.x\"]","}","","The following locations have been searched:"," /var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/.prisma/client"," /var/task/home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client"," /home/runner/work/ctfalcon-new/ctfalcon-new/node_modules/@prisma/client"," /tmp/prisma-engines"," at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)"," at process.emit (node:events:529:35)"," at emit (node:internal/process/promises:149:20)"," at processPromiseRejections (node:internal/process/promises:283:27)"," at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]} Unknown application error occurred Runtime.Unknown

I’ve tried to add preview-specific environment variables to the cloud on a specific Vercel branch with the Vercel CLI but I can’t connect a Git repository because the Git repository is in an organization and I need the team subscription for that. I have added prod environment variables to the cloud.

Is this because the workflows don’t add the DATABASE_URL and DIRECT_URL to the app?

Hey @InternetRamen :wave: Welcome!

So the fix for this issue is specified in the error message. You must update your schema.prisma file and specify the binaryTargets field. so you do:

generator client {
  provider = "prisma-client-js"
  binaryTargets   = ["native", "rhel-openssl-1.0.x"]
}

Could you please try making this change and letting me know if this fixes your issue?

1 Like

Hi @Mahmoud Thank you for responding! I added binaryTargets but I’m encountering this error now.

error: Environment variable not found: DATABASE_URL.
  -->  schema.prisma:12
   | 
   |     provider  = "PostgreSQL"
   |     url       = env("DATABASE_URL")
   | 

Hmm, when exactly do you run into this issue? When you open a PR or when you merge a PR to your main branch?

If it’s the latter, then you should have the DATABASE_URL variable defined in your repository’s secrets

1 Like

I’m running into this issue when I visit my SSR svelte preview page that loads the first row in a table (new commit on PR). I’m using Vercel Serverless functions to run the code.

I can’t add the env variables to the cloud bc my Git repo isn’t connected to Vercel, so I was wondering if there was a way to add it using the CLI and vercel deploy —prebuilt. I used echo ${{secrets.DATABASE_URL}} >> .env with the secrets in the Git repo. I’m following the preview branches CI/CD guide. Thank you so much!

Here is the PR: create card component create topics by InternetRamen · Pull Request #9 · Poolesville-Computer-Team/ctfalcon-new · GitHub

I actually updated the code for the demo to use the Neon CLI. I plan on updating the guide very soon.

In the meantime, do you mind trying out this code?

Feel free to ping me if you run into any issues

Hi @Mahmoud thanks for helping me out! I’m experiencing the same error as before with the new code. npx prisma generate works with the environment variables, but I think the variables aren’t pushed along with the build to Vercel.

Fixed the issue by adding

--env DATABASE_URL=$(neonctl cs ${{ steps.branch-name.outputs.current_branch }} --project-id ${{ secrets.NEON_PROJECT_ID }} --role-name ${{ secrets.PG_USERNAME }} --database-name ${{ secrets.NEON_DATABSE }} --api-key ${{ secrets.NEON_API_KEY }} --prisma --pooled) --env DIRECT_URL=$(neonctl cs ${{ steps.branch-name.outputs.current_branch }} --project-id ${{ secrets.NEON_PROJECT_ID }} --role-name ${{ secrets.PG_USERNAME }} --database-name ${{ secrets.NEON_DATABSE }} --api-key ${{ secrets.NEON_API_KEY }} --prisma)

to vercel deploy --prebuilt

1 Like

Hmm, I was unable to reproduce the issue. The Vercel CLI should be able to pick up the .env file :thinking: