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

Generated client output path hardcoded to build environment #7228

Closed
volkanunsal opened this issue May 22, 2021 · 6 comments · Fixed by #19330
Closed

Generated client output path hardcoded to build environment #7228

volkanunsal opened this issue May 22, 2021 · 6 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/aws-lambda topic: Query engine ... could not be found. Query engine ... for current platform ... could not be found.
Milestone

Comments

@volkanunsal
Copy link

volkanunsal commented May 22, 2021

I'm trying to deploy a lambda stack to AWS using @aws-cdk/aws-lambda-nodejs. This tool spins up a local Docker machine, mounts the current project directory to asset-input and mounts the build directory to asset-output, and compiles build artifacts from a source directory and pushes them to S3 and finally updates the lambda function.

Prior to deployment, I call prism generate to generate the client for the deployment target. But this command hardcodes the output path of the client to my local machine. I've tried using an env var:

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

But it has the same effect.

I'm not sure what can be done here, short of generating the client on the lambda app.

@volkanunsal
Copy link
Author

volkanunsal commented May 22, 2021

Here is the error I get when I hit that lambda:

Query engine binary for current platform "rhel-openssl-1.0.x" could not be found.

This probably happens, because you built Prisma Client on a different platform.
(Prisma Client looked in "/var/task/query-engine-rhel-openssl-1.0.x")

Searched Locations:
/.prisma/client
/Users/newuser/x/gr/serv/build/cdk.out/bundling-temp-fc45aec583972f9b53612ab574b1b09cf9a22cad40ebf910ba9b59e9f59ffe36/node_modules/@prisma/client
/var
/var/task
/var/task
/tmp/prisma-engines
/var/task

The path /Users/newuser/x/gr/serv/build/cdk.out/bundling-temp-fc45aec583972f9b53612ab574b1b09cf9a22cad40ebf910ba9b59e9f59ffe36/node_modules/@prisma/client is the hardcoded location of the output on my local machine.

How can I add a lookup path using an env var?

@volkanunsal
Copy link
Author

I fixed it by copying the engine to the output path:

afterBundling(inputDir: string, outputDir: string): string[] {
  return [
    `cp ${inputDir}/node_modules/.prisma/client/query-engine-rhel-openssl-1.0.x ${outputDir}/`,
  ];
},

I hope this is all we need from the client folder.

@janpio
Copy link
Member

janpio commented May 22, 2021

Where should the query engine binary be present in the deployment, what would be the correct path?
Can you maybe share more about how you build the project, maybe via a minimal reproduction repository?

@janpio janpio reopened this May 22, 2021
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. topic: deployment/aws-lambda labels May 22, 2021
@ryands17
Copy link

@volkanunsal 👋

From the solution, I assume you're using the CDK to bundle. One way to do this would be as shown here is generating the client directly in the asset instead of copying the query engine: https://github.com/ryands17/prisma-lambda/blob/main/lib/prisma-lambda-stack.ts#L31-L36

@volkanunsal
Copy link
Author

volkanunsal commented May 24, 2021 via email

@janpio janpio added the team/client Issue for team Client. label May 31, 2021
@janpio janpio added the topic: Query engine ... could not be found. Query engine ... for current platform ... could not be found. label Jan 28, 2023
@millsp millsp added this to the 4.15.0 milestone May 24, 2023
@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.

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/aws-lambda 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.

4 participants