-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
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.__dirnameto 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: truein 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!