Skip to content

prisma client doesn't work with serverless-next.js #6032

@jeremygottfried

Description

@jeremygottfried

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.

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:

  1. Use WebpackCopyPlugin to copy prisma client files in correct location
  2. Use a postinstall script to generate prisma client manually
  3. use a post build script to generate prisma client manually
  4. Override node.__dirname to be false in production (for nextjs webpack config)
  5. Move @prisma/cli to dependencies instead of devDependencies
  6. Use WebpackPermissionsPlugin to change binary fileMode to 755 (for prisma client files)
  7. Copy prisma client files to tmp during execution
  8. Set useServerlessTraceTarget: true in serverless.yml
  9. Change prisma output parameter so it's generated outside of node_modules
  10. 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!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions