Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Engine Library Not Found #13396

Closed
VictorArowo opened this issue May 17, 2022 · 20 comments · Fixed by #19330
Closed

Query Engine Library Not Found #13396

VictorArowo opened this issue May 17, 2022 · 20 comments · Fixed by #19330
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: deployment/vercel topic: Query engine ... could not be found. Query engine ... for current platform ... could not be found.
Milestone

Comments

@VictorArowo
Copy link

VictorArowo commented May 17, 2022

Bug description

We have recently been seeing query engine library errors on our app hosted on vercel. This has been happening for about a day and suddenly started happening intermittently. This is really weird because it says it wants "rhel-openssl-1.1.x" and that we incorrectly pinned to "rhel-openssl-1.1.x".
We have tried to explicitely add binaryTargets = ["native", "rhel-openssl-1.0.x", "rhel-openssl-1.1.x"], but this causes our build to fail with function size errors.
I would appreciate any pointers here.

Query engine library for current platform "rhel-openssl-1.1.x" could not be found.
You incorrectly pinned it to rhel-openssl-1.1.x

This probably happens, because you built Prisma Client on a different platform.
(Prisma Client looked in "/var/task/node_modules/@prisma/client/ultron/runtime/libquery_engine-rhel-openssl-1.1.x.so.node")

Searched Locations:

  /var/task/node_modules/@prisma/.prisma/client
  /vercel/path0/node_modules/@prisma/client/ultron
  /var/task/node_modules/@prisma/client/ultron
  /var/task/node_modules/@prisma/client/ultron
  /var/task/node_modules/@prisma/client/ultron
  /tmp/prisma-engines
  /var/task/node_modules/@prisma/client/ultron


To solve this problem, add the platform "rhel-openssl-1.1.x" to the "binaryTargets" attribute in the "generator" block in the "schema.prisma" file:
generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native"]
}

Then run "prisma generate" for your changes to take effect.
Read more about deploying Prisma Client: https://pris.ly/d/client-generator

I see a related issue here: #13266

How to reproduce

It currently seems to cause random requests to error out. I am not able to identify a pattern here.

Expected behavior

I expect the right query engine library to be used.

Prisma information

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

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["filterJson", "dataProxy"]
  output          = "../../../../node_modules/@prisma/client/ultron"
}

generator dbml {
  provider = "prisma-dbml-generator"
}

Environment & setup

This is currently happening on vercel's serverless platform which I believe uses AWS.

Prisma Version

prisma                  : 3.11.1
@prisma/client          : 3.11.1
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 1a2506facaf1a4727b7c26850735e88ec779dee9 (at node_modules/prisma/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 1a2506facaf1a4727b7c26850735e88ec779dee9 (at node_modules/prisma/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 1a2506facaf1a4727b7c26850735e88ec779dee9 (at node_modules/prisma/node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 1a2506facaf1a4727b7c26850735e88ec779dee9 (at node_modules/prisma/node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash    : 1a2506facaf1a4727b7c26850735e88ec779dee9
Studio                  : 0.458.0
@VictorArowo VictorArowo added the kind/bug A reported bug. label May 17, 2022
@janpio
Copy link
Member

janpio commented May 18, 2022

Are you saying this is happening to some request but not all? That is super weird.
Did you have any binaryTargets value in your schema file before?
Does it work if you just do binaryTargets = ["native", "rhel-openssl-1.1.x"]? (Where does the rhel-openssl-1.0.x come from?)
Did you change anything about your deployment recently that could explain why this started happening? Any deps updates?

@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. topic: deployment/vercel labels May 18, 2022
@VictorArowo
Copy link
Author

Yes. This is happening intermittently, causing random requests to fail.
We never specified binaryTargets in anyway prior to this. And specifying ["native", "rhel-openssl-1.1.x"] also causes our builds to fail with function size errors.
We have temporarily just pinned to binaryTargets = ["rhel-openssl-1.1.x"], but this obviously does not work for local development, as we have to switch to native.

@janpio
Copy link
Member

janpio commented May 18, 2022

That is super weird. Can you maybe reach out to Vercel and ask if anything changed on their environment? Fundamentally I would debug this by checking the actual location of the so.node file during the build/deployment and see if the fiel might actually be there, or if not, what other files are there. So adding some manual output to the build comment maybe.

@williamoverton
Copy link

I am getting this error in AWS lambda node16.x

Error: Query engine library for current platform "rhel-openssl-1.0.x" could not be found.
You incorrectly pinned it to rhel-openssl-1.0.x

@VictorArowo
Copy link
Author

@janpio I fixed this by hard-pinning to the right version per environment

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["filterJson", "dataProxy"]
  output          = "../../../../node_modules/@prisma/client/ultron"
  binaryTargets   = env("PRISMA_BINARY_TARGET")
}

@jschuur
Copy link

jschuur commented Aug 9, 2022

I've tried @VictorArowo's approach, but still running into issues. Bizarrely, the error is pretty contradictory:

Query engine library for current platform "darwin-arm64" could not be found.
You incorrectly pinned it to darwin-arm64

In my particular implementation, I'm using this in a Yarn workspaces monorepo (test repo) with serverless-webpack-prisma. The same monorepo also reuses this Prisma client from a shared package in a Next.js site workspace, and Prisma works fine there, making me think my problem might actually be more specific to serverless-webpack-prisma (I've also asked there in this issue.

More detailed error message:

❮ sls invoke local -f videos -s local                                                                                              09:02 Lise
DOTENV: Could not find .env file.

asset src/videos.js 1.19 MiB [emitted] (name: src/videos)
  asset src/schema.prisma 4.61 KiB [emitted] [from: ../../packages/prisma/prisma/schema.prisma] [copied]
  cacheable modules 1.13 MiB
    modules by path ../../node_modules/@prisma/client/ 1.1 MiB
      ../../node_modules/@prisma/client/index.js 59 bytes [built] [code generated]
      ../../node_modules/@prisma/client/runtime/index.js 1.1 MiB [built] [code generated]
    ./src/videos.js 372 bytes [built] [code generated]
    ../../node_modules/.prisma/client/index.js 29.2 KiB [built] [code generated]
  + 21 modules
  webpack 5.74.0 compiled successfully in 375 ms

PrismaClientInitializationError: 
Invalid `prisma.video.findMany()` invocation:


  Query engine library for current platform "darwin-arm64" could not be found.
You incorrectly pinned it to darwin-arm64

This probably happens, because you built Prisma Client on a different platform.
(Prisma Client looked in "/Users/joostschuur/Code/Personal/_Tests/yarn-workspaces-prisma-nextjs-serverless/services/backend/.webpack/service/src/libquery_engine-darwin-arm64.dylib.node")

Searched Locations:

  /Users/joostschuur/Code/Personal/_Tests/yarn-workspaces-prisma-nextjs-serverless/services/backend/.prisma/client
  /Users/joostschuur/Code/Personal/_Tests/yarn-workspaces-prisma-nextjs-serverless/node_modules/@prisma/client
  /Users/joostschuur/Code/Personal/_Tests/yarn-workspaces-prisma-nextjs-serverless/services/backend/.webpack/service
  /Users/joostschuur/Code/Personal/_Tests/yarn-workspaces-prisma-nextjs-serverless/services/backend/.webpack/service/src
  /Users/joostschuur/Code/Personal/_Tests/yarn-workspaces-prisma-nextjs-serverless/services/backend/.webpack/service/src
  /tmp/prisma-engines
  /Users/joostschuur/Code/Personal/_Tests/yarn-workspaces-prisma-nextjs-serverless/services/backend/.webpack/service/src

You already added the platform "darwin-arm64" to the "generator" block
in the "schema.prisma" file as described in https://pris.ly/d/client-generator,
but something went wrong. That's suboptimal.

Please create an issue at https://github.com/prisma/prisma/issues/new
    at RequestHandler.handleRequestError (webpack://backend/../../node_modules/@prisma/client/runtime/index.js?:28655:13)
    at PrismaClient._getDmmf (webpack://backend/../../node_modules/@prisma/client/runtime/index.js?:29727:23)
    at async PrismaClient._executeRequest (webpack://backend/../../node_modules/@prisma/client/runtime/index.js?:29648:22)
    at async consumer (webpack://backend/../../node_modules/@prisma/client/runtime/index.js?:29607:18)
    at async PrismaClient._request (webpack://backend/../../node_modules/@prisma/client/runtime/index.js?:29626:16)
    at async module.exports.handler (webpack://backend/./src/videos.js?:8:18) {
  clientVersion: '4.1.1',
  errorCode: undefined
}

@janpio
Copy link
Member

janpio commented Aug 9, 2022

Thanks @jschuur, I think your description and reproduction is specific enough that you can open a new issue and fill the template - then we can look at yours in isolation. Thanks!

@jschuur
Copy link

jschuur commented Aug 10, 2022

Thanks @jschuur, I think your description and reproduction is specific enough that you can open a new issue and fill the template - then we can look at yours in isolation. Thanks!

The above error seemed to be resolved, once I went and added an output setting to the generator client definition, so it doesn't really look like a new bug, just something that is not well documented.

However, then I had trouble deploying it to Vercel with Yarn (frozen lock file error due to Vercel running Yarn with a 1.x option that was deprecated in Berry) and ended up trying out pnpm.

Now all of a sudden it won't find the client module anymore (test repo):

./pages/api/prisma.js:1:0
Module not found: Can't resolve './node_modules/.prisma/client '
> 1 | import { PrismaClient } from './node_modules/.prisma/client ';
  2 | 
  3 | const prisma = new PrismaClient();
  4 | 

I know this is no longer on topic for this thread, but I have been trying to sort this out all day and will have to file a proper bug report in the morning.

Morning edit: It looks like importing '.prisma/client' fixed this error, but now Next.js is complaining about not finding schema.prisma in a local location (where it obviously isn't). This is also a known issue (running prisma 4.2.0 and next 12.2.4), so I'll move on to an existing thread about this.

@RoryKelly
Copy link

RoryKelly commented Oct 2, 2022

I think the cause of this issue is that Prisma is not searching the correct directory for the binary.

in my case I am compiling for AWS lambda, I get the error:

Query engine library for current platform \rhel-openssl-1.0.x\ could not be found.
You incorrectly pinned it to rhel-openssl-1.0.x

This probably happens because you built Prisma Client on a different platform.
(Prisma Client looked in \/var/task/src/libquery_engine-rhel-openssl-1.0.x.so.node\)

Searched Locations:

  /.prisma/client
  /home/runner/work/8bars/8bars/backend-v2/node_modules/@prisma/client
  /var/task
  /var/task/src
  /var/task/src
  /tmp/prisma-engines
  /var/task/src

You already added the platforms \debian-openssl-1.1.x\ \rhel-openssl-1.0.x\ to the \generator\ block
in the \schema.prisma\ file as described in https://pris.ly/d/client-generator
but something went wrong. That's suboptimal.

looking at the search paths it is missing

  /home/runner/work/8bars/8bars/backend-v2/node_modules/.prisma/client

The binaries are located here and not in the @prisma/client directory

@nwalters512
Copy link

nwalters512 commented Oct 3, 2022

Possibly relevant: I'm using Vercel's ncc to "compile" some JavaScript into a single file for deployment to AWS Lambda, and I also get this error at runtime, even after updating binaryTargets to include rhel-openssl-1.0.x as the error message suggests. I believe Vercel internally uses ncc + AWS Lambda, so this is likely the same underlying problem.

When ncc spits out files into a directory, I end up with an index.js file and client/libquery_engine-rhel-openssl-1.0.x.so.node. However, /var/task/client isn't in the list of "Searched Locations". I believe there are a few ways I could resolve this on my own:

  • Copy libquery_engine-rhel-openssl-1.0.x.so.node to /tmp/prisma-engines at runtime
  • Copy it from $OUT_DIR/client to $OUT_DIR/ as a post-ncc step

That said, it would be great if this worked out of the box!

@ibvodafoneziggo
Copy link

We've set the engine location by using the given ENV engine variables. It seems like Prisma doesn't look at these ENV values when looking for the binaries during application initialization.

To reproduce

  1. set the ENV variables here https://www.prisma.io/docs/concepts/components/prisma-engines#using-custom-engine-libraries-or-binaries to a custom location by using ENV PRISMA_QUERY_ENGINE_BINARY=/custom/something in a Dockerfile.
  2. Build dockerfile
  3. Build application in Dockerfile
  4. Run application in dockerfile

Problem occurs during running the application.

@janpio
Copy link
Member

janpio commented Dec 8, 2022

PRISMA_QUERY_ENGINE_BINARY is only used when the Client is set to use the binary engine type. By default is used library and only that environment variable is used.

@ibvodafoneziggo
Copy link

I've found what goes wrong.

When you supply PRISMA_CLIENT_ENGINE_TYPE=library and you set the location of the library as PRISMA_QUERY_ENGINE_LIBRARY=/library/location, it doesn't listen to the PRISMA_QUERY_ENGINE_LIBRARY.

It does work for the binary, and it will listen to that location, but for library it doesn't.

We've now set it back to the binary and the binary lookup step goes succesful.

@janpio
Copy link
Member

janpio commented Dec 9, 2022

Can you please open a bug report for this? That should definitely not be the case and we need to check and fix that. Thanks!

@carlmlane
Copy link

carlmlane commented Dec 14, 2022

@ibvodafoneziggo I can also recreate that the environment variable doesn't allow for overriding the engine library via PRISMA_QUERY_ENGINE_LIBRARY. Will see if forcing to use binary instead will work for my implementation.

I will try to also document steps to recreate for a bug report if I get time in the next few days.

update: @ibvodafoneziggo is correct in that the PRISMA_QUERY_ENGINE_LIBRARY env var doesn't work at runtime and falling back to the binary file via PRISMA_QUERY_ENGINE_BINARY is a workaround in my scenario and works at both generate and runtime.

@janpio janpio added topic: Query engine ... could not be found. Query engine ... for current platform ... could not be found. and removed topic: You incorrectly pinned it to ... labels Jan 28, 2023
@fattila16
Copy link

fattila16 commented Feb 18, 2023

Don't know whether this helps anyone. But let me share my experience and fix for this error.

Some context:

  • I am running prisma on AWS Lambda. Runtime is node:16.
  • I am using two generated clients, one for cockroach one for sqlite.
    • In the end these end up in different lambdas, but I am developing them in the same repository
  • They are generated in node_modules/.prisma/sqlite and node_modules/.prisma/cockroach.
  • I am using aws-cdk/aws-lambda-nodejs to package lambdas.
  • I am manually deleting unnecessary generated things in order to decrease the bundle size
    • node_modules/prisma node_modules/@prisma/engines
    • and unnecessary libquery_engine files generated on the CI

In order to fix the Query engine library for current platform "rhel-openssl-1.0.x" could not be found. I had to explicitly set the PRISMA_QUERY_ENGINE_LIBRARY env var for the lambdas to point to the library files.

PRISMA_QUERY_ENGINE_LIBRARY: './node_modules/.prisma/sqlite/libquery_engine-rhel-openssl-1.0.x.so.node',
PRISMA_QUERY_ENGINE_LIBRARY: './node_modules/.prisma/cockroach/libquery_engine-rhel-openssl-1.0.x.so.node',

Little specific setup and an ugly solution but it works out in the end.

@bowencool
Copy link

Don't know whether this helps anyone. But let me share my experience and fix for this error.

Some context:

  • I am running prisma on AWS Lambda. Runtime is node:16.

  • I am using two generated clients, one for cockroach one for sqlite.

    • In the end these end up in different lambdas, but I am developing them in the same repository
  • They are generated in node_modules/.prisma/sqlite and node_modules/.prisma/cockroach.

  • I am using aws-cdk/aws-lambda-nodejs to package lambdas.

  • I am manually deleting unnecessary generated things in order to decrease the bundle size

    • node_modules/prisma node_modules/@prisma/engines
    • and unnecessary libquery_engine files generated on the CI

In order to fix the Query engine library for current platform "rhel-openssl-1.0.x" could not be found. I had to explicitly set the PRISMA_QUERY_ENGINE_LIBRARY env var for the lambdas to point to the library files.

PRISMA_QUERY_ENGINE_LIBRARY: './node_modules/.prisma/sqlite/libquery_engine-rhel-openssl-1.0.x.so.node',
PRISMA_QUERY_ENGINE_LIBRARY: './node_modules/.prisma/cockroach/libquery_engine-rhel-openssl-1.0.x.so.node',

Little specific setup and an ugly solution but it works out in the end.

This works for me, thank you. BTW, you can add the following config to your serverless.yml to exclude unnecessary generated files, and you can find documentation here

package:
  patterns:
    - '!node_modules/prisma/**'
    - '!node_modules/@prisma/engines/**'

@millsp
Copy link
Member

millsp commented May 31, 2023

Hey, we wanted to give you an update about this. We have around 10 issues that we have identified to be in the "engine not found" category. Looking at these, we learned that there are four main categories responsible for these errors:

  • Your client was generated with native (default) on one platform, but used on a different platform at runtime.
  • You pinned binaryTargets incorrectly, and the correct engine was therefore not included at runtime.
  • A bundler/framework changed the Prisma Client but did not copy the necessary engine for the runtime.
  • Deployment/tooling did not copy the engine correctly so the correct engine was not included at runtime.

These cases were previously not detected. On top of that, the error messages were confusing and were neither helpful for you or us. With that, it is likely that many of the cases above overlapped each other. So while we cannot fix a missing engine, we can detect how and why it happened. Thanks to that, we now display more useful errors to help you out of trouble. And in some cases, we will ask some input from you to learn more about your project so we can further improve.

If something is still off for you, feel free to create a new issue.

@khanhhuy
Copy link

+1 for @millsp just said.
I used Mac M1, and installed Node under Rosetta. Then later I re-installed Node using Arm, started my server with Prisma, and encountered the error Query engine library for current platform "darwin-arm64" could not be found

The solution for my case is to re-run prisma generate under Arm

@charanjit-singh
Copy link

I'm getting this in vercel production

/var/lang/bin/node: Relink `/var/task/node_modules/.pnpm/@prisma+client@5.12.1_prisma@5.12.1/node_modules/.prisma/client/libquery_engine-rhel-openssl-1.0.x.so.node' with `/lib64/librt.so.1' for IFUNC symbol `clock_gettime'
/var/lang/bin/node: Relink `/var/task/node_modules/.pnpm/@prisma+client@5.12.1_prisma@5.12.1/node_modules/.prisma/client/libquery_engine-rhel-openssl-1.0.x.so.node' with `/lib64/librt.so.1' for IFUNC symbol `clock_gettime'
Error: Runtime exited without providing a reason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: deployment/vercel topic: Query engine ... could not be found. Query engine ... for current platform ... could not be found.
Projects
None yet
Development

Successfully merging a pull request may close this issue.