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

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

Closed
jeremygottfried opened this issue Mar 9, 2021 · 17 comments
Closed

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

jeremygottfried opened this issue Mar 9, 2021 · 17 comments
Assignees
Labels
Milestone

Comments

@jeremygottfried
Copy link

jeremygottfried commented Mar 9, 2021

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!

@janpio
Copy link
Member

janpio commented Mar 9, 2021

Possibly related: #6020

@Jolg42 Jolg42 added 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: aws lambda topic: binary topic: Next.js topic: prisma-client topic: serverless labels Mar 11, 2021
@s-kris
Copy link

s-kris commented Mar 12, 2021

similar issue when deployed on netlify: #6051

@pantharshit00
Copy link
Contributor

Can you share a reproduction repository which we can use to test this out?

@jeremygottfried
Copy link
Author

jeremygottfried commented Mar 18, 2021

I tried to create one, but now I can't even get it to deploy. I'm hitting a new error, which also seems to be caused by prisma:

Build error occurred
TypeError: debugLib is not a function
at Object. (/Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.next/serverless/pages/index.js:3452:15)
at Object.6Z5O (/Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.next/serverless/pages/index.js:3642:30)
at webpack_require (/Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.next/serverless/pages/index.js:23:31)
at Object. (/Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.next/serverless/pages/index.js:41404:65)
at Object.Kg+b (/Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.next/serverless/pages/index.js:41416:30)
at webpack_require (/Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.next/serverless/pages/index.js:23:31)
at Object.1ygI (/Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.next/serverless/pages/index.js:1742:72)
at webpack_require (/Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.next/serverless/pages/index.js:23:31)
at Module.23aj (/Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.next/serverless/pages/index.js:1768:69)
at webpack_require (/Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.next/serverless/pages/index.js:23:31) {
type: 'TypeError'
}
info - Loaded env from /Users/jeremygottfried/Development/nextjs-prisma-serverless-bug/nextjs-prisma-serverless-bug/.env
info - Creating an optimized production build...
info - Collecting page data...

https://github.com/jeremygottfried/nextjs-prisma-serverless-bug

If you can help me fix that error, then I can reproduce the original bug. I commented out the next-auth code in index.tsx, but ideally dependencies that use prisma should also work on serverless.

To deploy, you just run serverless in the command line.

@s-kris
Copy link

s-kris commented Mar 18, 2021

@jeremygottfried @pantharshit00 error seems to be consistent with #6051

@jeremygottfried
Copy link
Author

@jeremygottfried @pantharshit00 error seems to be consistent with #6051

Yup that makes sense because I originally had the bug on prisma 2.16.1, but the new repo is on 2.19.0

@jdcookie
Copy link

jdcookie commented Mar 19, 2021

I am seeing the same issue just trying to run serverless:offline - nothing to do with serverless-nextjs

offline: GET /dev/hello (λ: hello)
offline: Failure: debugLib is not a function
TypeError: debugLib is not a function
at Object.../../../packages/data-models/node_modules/.prisma/client/index.js (/Users/jcook/Code/cls-plus-backend-v2/clsp-app/services/socket-score-publish/.webpack/service/webpack:/Users/jcook/Code/cls-plus-backend-v2/clsp-app/packages/data-models/node_modules/.prisma/client/index.js:21:1)

"prisma": "^2.19.0",

@pantharshit00
Copy link
Contributor

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.

@jonahallibone
Copy link

jonahallibone commented Mar 19, 2021

@jeremygottfried AFAIK the solution I mentioned in my issue still works, (even though it's not ideal depending on binary size). I haven't heard from anyone about how to preserve or change the permissions after then fact from your deploy script. I am wondering if a solution like this is possible to use instead of my copying to '/tmp' but I haven't tried it. That being said, I'm not using netlify so they might have some better built in process to handle this situation than I do.

@millsp
Copy link
Member

millsp commented May 10, 2021

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.

@nabi-chan
Copy link

nabi-chan commented May 11, 2021

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

@matthewmueller matthewmueller modified the milestones: 2.23.0, 2.24.0 May 19, 2021
@pantharshit00
Copy link
Contributor

Hello everyone

Can you please also try reproducing this with the latest version?

@jeremygottfried
Copy link
Author

Hello everyone

Can you please also try reproducing this with the latest version?

@pantharshit00 I think @KimPinot was referring to the debugLib bug, not the "binary could not be found" issue.

@nabi-chan
Copy link

nabi-chan commented May 25, 2021

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.

@matthewmueller matthewmueller modified the milestones: 2.24.0, 2.25.0 Jun 2, 2021
@millsp
Copy link
Member

millsp commented Jun 8, 2021

Marking this as solved as it is a configuration problem

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.

@millsp millsp closed this as completed Jun 8, 2021
@jeremygottfried
Copy link
Author

@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.

@millsp
Copy link
Member

millsp commented Jun 8, 2021

No worries, we're working on it with the docs team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants