prisma: Can't find prisma binary on vercel serverless function

Bug description

When I deploy my project on vercel, It always throws this error. It seems generating prisma client not work. Tested on pnpm 8.6.8, yarn 1.22.18

Unhandled rejection: PrismaClientInitializationError: Prisma Client could not locate the Query Engine for runtime "rhel-openssl-1.0.x".

This is likely caused by a bundler that has not copied "libquery_engine-rhel-openssl-1.0.x.so.node" next to the resulting bundle.
Ensure that "libquery_engine-rhel-openssl-1.0.x.so.node" has been copied next to the bundle or in "node_modules/.pnpm/@prisma+client@5.6.0_prisma@5.6.0/node_modules/.prisma/client".

We would appreciate if you could take the time to share some information with us.
Please help us by answering a few questions: https://pris.ly/engine-not-found-bundler-investigation

The following locations have been searched:
  /var/task/node_modules/.pnpm/@prisma+client@5.6.0_prisma@5.6.0/node_modules/.prisma/client
  /var
  /vercel/path0/node_modules/.pnpm/@prisma+client@5.6.0_prisma@5.6.0/node_modules/@prisma/client
  /.prisma/client
  /tmp/prisma-engines
    at il (/var/task/index.js:67:805)
    at async Object.loadLibrary (/var/task/index.js:114:9808)
    at async Wt.loadEngine (/var/task/index.js:115:448)
    at async Wt.instantiateLibrary (/var/task/index.js:114:19566) {
  clientVersion: '5.6.0',
  errorCode: undefined
}
Error: Runtime exited with error: exit status 1
Runtime.ExitError

How to reproduce

  1. Clone this repo nabi-chan/vercel-test
  2. deploy it to vercel
  3. after build, enter the deployment
  4. It reproduced!

Expected behavior

Find prisma binary and correctly works

Prisma information

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id    Int    @id @default(autoincrement())
  email String @unique

  name     String?
  password String

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}
const prisma = new PrismaClient();

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v20.10.0
  • Package Manager : pnpm

Prisma Version

prisma                  : 5.6.0
@prisma/client          : 5.6.0
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v16.15.0
Query Engine (Node-API) : libquery-engine e95e739751f42d8ca026f6b910f5a2dc5adeaeee (at node_modules/.pnpm/@prisma+engines@5.6.0/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli e95e739751f42d8ca026f6b910f5a2dc5adeaeee (at node_modules/.pnpm/@prisma+engines@5.6.0/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.6.0-32.e95e739751f42d8ca026f6b910f5a2dc5adeaeee
Default Engines Hash    : e95e739751f42d8ca026f6b910f5a2dc5adeaeee
Studio                  : 0.495.0

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 6
  • Comments: 24 (3 by maintainers)

Most upvoted comments

@rnnyrk Here is what my next.config.mjs file looks like. This file is under /apps/<app name>/next.config.mjs in my project.

import { PrismaPlugin } from '@prisma/nextjs-monorepo-workaround-plugin'

/** @type {import('next').NextConfig} */
const nextConfig = {
  transpilePackages: ["@workspace/ui"],
  webpack: (config, { isServer }) => {
    // This is a workaround to avoid this Prisma issue on Vercel
    // https://github.com/prisma/prisma/discussions/19499
    if (isServer) {
      config.plugins = [...config.plugins, new PrismaPlugin()]
    }

    return config
  },
}

export default nextConfig

Ah, I see that you have committed an older version of Prisma in the reproduction repository, and when undoing that commit (https://github.com/janpio/nabi-chan-vercel-test/tree/prisma5) I get the same error message that you reported:

Unhandled rejection: PrismaClientInitializationError: Prisma Client could not locate the Query Engine for runtime "rhel-openssl-1.0.x".

This is likely caused by a bundler that has not copied "libquery_engine-rhel-openssl-1.0.x.so.node" next to the resulting bundle.
Ensure that "libquery_engine-rhel-openssl-1.0.x.so.node" has been copied next to the bundle or in "node_modules/.pnpm/@prisma+client@5.6.0_prisma@5.6.0/node_modules/.prisma/client".

We would appreciate if you could take the time to share some information with us.
Please help us by answering a few questions: https://pris.ly/engine-not-found-bundler-investigation

The following locations have been searched:
  /var/task/node_modules/.pnpm/@prisma+client@5.6.0_prisma@5.6.0/node_modules/.prisma/client
  /var
  /vercel/path0/node_modules/.pnpm/@prisma+client@5.6.0_prisma@5.6.0/node_modules/@prisma/client
  /.prisma/client
  /tmp/prisma-engines
    at il (/var/task/index.js:67:805)
    at async Object.loadLibrary (/var/task/index.js:114:9808)
    at async Wt.loadEngine (/var/task/index.js:115:448)
    at async Wt.instantiateLibrary (/var/task/index.js:114:19566) {
  clientVersion: '5.6.0',
  errorCode: undefined
}

I’ve been facing this issue myself and have found that the issue with Vercel seems to stem from the following:

  • Having two instances of prisma within the app – for example, one for auth and one for application logic
  • Using the generator output in the schema

If you have a basic app which is just using one instance of Prisma and do not change the generator output, everything works as expected. When you add a generator output it looks as though Vercel’s deployment pipeline does not copy over the engine which is where the issue is stemming from.

Facing the same issue, is there any workaround ? I’m using turborepo.

Is there no other fix here? @Illyism’s solution is going to be deprecated in two-ish months with Prisma 7

@matiasdecarli seems that we have the very same config in our projects… TBH most of this things usually happen with new versions of NextJS, especially when working with also new versions of other packages like Turborepo or Prisma…

Seems that for now it is not possible to run this setup in the Edge, so I’m fixing it adding optimistic UI patterns instead until we have a more clear answer about how to setup this combo (Next + Prisma + Turborepo) in the edge.

Are there any updates on this? I’m having the same error, I cannot run my container based on my image

PrismaClientInitializationError: Prisma Client could not locate the Query Engine for runtime "darwin-arm64".

This is likely caused by a bundler that has not copied "libquery_engine-darwin-arm64.dylib.node" next to the resulting bundle.
Ensure that "libquery_engine-darwin-arm64.dylib.node" has been copied next to the bundle or in "packages/api/dist".

We would appreciate if you could take the time to share some information with us.
Please help us by answering a few questions: https://pris.ly/engine-not-found-bundler-investigation

I’m using turborepo with tsup [bundling an express js app with trpc]