prisma: prisma client doesn't work with serverless-next.js
Serverless-next.js doesn’t work with prisma client. It seems like the issue is the binaries either don’t have the correct permissions or they’re not in the correct location.
The serverless.com component deploys NextJS to AWS lambda edge, S3 and cloudfront. The issue seems to occur in the lambda execution environment.
Error:
ERROR [next-auth][error][get_user_by_provider_account_id_error] https://next-auth.js.org/errors#get_user_by_provider_account_id_error PrismaClientInitializationError2 [PrismaClientInitializationError]: 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 “/tmp/query-engine-rhel-openssl-1.0.x”)
Searched Locations:
You already added the platforms “native”, “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.
Please create an issue at https://github.com/prisma/prisma-client-js/issues/new at PrismaClientFetcher.request (/var/task/pages/api/auth/[…nextauth].js:151931:15) at processTicksAndRejections (internal/process/task_queues.js:97:5) { clientVersion: ‘2.16.1’ }
This issue seems to be well documented for various use cases.
- serverless-next.js#843
- prisma/docs#841
- next-auth#1191
- prisma/prisma#2195
- prisma-client-js#616
- prisma/prisma#5392
I spent 2 days trying to debug this using many different solutions, proposed in the issues above, but I haven’t fixed it yet. All the solutions have either caused the deployment to error out, or didn’t change anything.
The proposed solutions have been:
- Use WebpackCopyPlugin to copy prisma client files in correct location
- Use a postinstall script to generate prisma client manually
- use a post build script to generate prisma client manually
- Override
node.__dirname
to be false in production (for nextjs webpack config) - Move @prisma/cli to dependencies instead of devDependencies
- Use WebpackPermissionsPlugin to change binary fileMode to
755
(for prisma client files) - Copy prisma client files to tmp during execution
- Set
useServerlessTraceTarget: true
in serverless.yml - Change prisma output parameter so it’s generated outside of node_modules
- Try the latest alpha release of serverless-next.js
Again, none of these solutions have fixed it for me. If anyone has a workaround that will fix this universally, I would be very grateful!
Prisma client setup:
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "rhel-openssl-1.0.x"]
}
- OS/Environment: macOS Catalina 10.15.1
- @sls-next/serverless-component version: 1.18.0 and latest alpha version
- Next.js version: 10.0.5
- prisma client version: 2.16.1
- prisma version: 2.16.1
- serverless components version: 3.4.2
serverless.yml
myNextApp:
org: myOrg
stage: prod
component: "@sls-next/serverless-component@1.18.0" # it is recommended you pin the latest stable version of serverless-next.js
inputs:
bucketName: myApp-nextjs
name: myApp
@achraf-boussaada, @jonahallibone, @vaskevich, @colinhacks seemed to be facing similar issues, so if any of you have ideas, that would be helpful!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 17 (7 by maintainers)
I will consider this blocked by #6051, we will patch that first then we can have another look here and hopefully this will be fixed as well.
I turns out that the binaries were not copied into the lambda. This could be solved by adding a script that triggers before upload. I have set a template up for prisma + serverless-next.js which adds a
postBuildCommands
(serverless.yml
) script to do just that.No worries, we’re working on it with the docs team.
@millsp Is it possible for prisma to officially support this config? I feel like the config should at least be documented so people don’t keep coming back with the same issue.
Oh sorry. I forgot to mention it. Thanks @jeremygottfried.
I used prisma ‘2.22.1’ for solve ‘debuglib’ issue.
Also, I solved ‘binary is not found’ issue using https://github.com/millsp/prisma-serverless-nextjs . This repo moves binary and schema files into api and default-lambda folders when build and deploy nextjs-serverless app.
@pantharshit00 I think @KimPinot was referring to the
debugLib
bug, not the “binary could not be found” issue.Hello! I also had this issue about ‘debugLib’ bug.
The issue disappeared when I upgraded the version of Prisma and @prisma/client to the latest (^2.22.1) version!
Reference: https://answers.netlify.com/t/netlify-wont-deploy-my-next-js-prisma-app/34716/5
I am seeing the same issue just trying to run serverless:offline - nothing to do with serverless-nextjs
“prisma”: “^2.19.0”,