-
Notifications
You must be signed in to change notification settings - Fork 67
Prisma does not seem to get rhel binary in functions #55
Comments
Hi @garrypolley, I think your assessment of the issue (rhel binary not shipping) might be exactly right. We've seen this kind of issue before when using packages that rely on binaries/native code. NextJS' strategy for creating serverless functions is to inline the code from all dependencies into a big JS file. That works really well, except when binaries are involved. Given that everything works when you If you have time and interest, it would be great if you could set up a minimal repo for reproducing the issue (just with one really simple API endpoint that uses Prisma, for example). Otherwise, I will try to make some time for this tomorrow. We should definitely be able to get this working 👍 Thanks for taking the time to report this issue! 😊 |
@FinnWoelm I appreciate the feedback. Here is a basic repo that does work: https://github.com/garrypolley/deployment-example-netlify. |
Yap, that's super helpful already! What I want to do next is to create a version that uses So for this test case, we would not run our build command on netlify.com. We would instead locally run |
@FinnWoelm I can confirm the I used a custom build plugin:
this copied them to the
At the point they they then get "zipped" up and sent to lambda they seem to lack the rhel file. I'm not sure where to put the binary at -- I even tried to manually put them in the code base, since the client is dynamically generated. This didn't work either, though I may have done something incorrectly. EDIT I just noticed this:
You mean to manually try it -- I have not done that. I can give that a whirl. |
Hey @garrypolley, thanks to your excellent repo, I was able to reproduce the issue and behavior! I understand the issue now; brace yourself for a brief rollercoaster — and a beautiful solution at the end 😊 Rollercoaster 🎢When NextJS creates the serverless functions for the API endpoints, it hardcodes the names and even paths of the prisma binaries into the function code. That obviously leads to issues. For example: https://github.com/FinnWoelm/next-on-netlify-prisma/blob/beb399075f1018b18254545cb06cc2610e512fb8/out_functions/next_api_test/nextJsPage.js#L526 We can get around that by wrapping the Now, this leads to one more issue, namely that Netlify does not know that it needs to bundle prisma into the Netlify Function. So we need to have a noop-require in the function handler (this one does not get touched by NextJS, so no inlining happens). Example: https://github.com/FinnWoelm/next-on-netlify-prisma/blob/beb399075f1018b18254545cb06cc2610e512fb8/out_functions/next_api_test8/next_api_test8.js#L4 You can see everything working here: https://compassionate-euler-d2be4d.netlify.app/.netlify/functions/next_api_test8 (well, except, that I don't have Prisma set up nor the DATABASE_URL configured). But compare with https://compassionate-euler-d2be4d.netlify.app/.netlify/functions/next_api_test and you will see the difference. Solution 🌞Don't fear! You do not actually need to In fact, we should probably tell everyone to switch over to Would you mind trying |
Thanks @FinnWoelm this fixed it entirely. Using the config
This is great, and I'm glad it was this easy to fix. I'm appreciative of the time you've taken here! Consider this done. |
This change in the readme is to help future developers not have binary issues across lambda functions created by the next build command.
This change does seem to make it slower to deploy. |
For future developers that may google their way here. There is an issue (October 15 2020) where Prisma needs to be disconnected after all calls on any function. Your lambda will timeout otherwise. You'll need to do. //after all your DB calls, before the `res.json` call
await prismaClientInstance.$disconnect(); For details see: https://github.com/prisma/prisma-client-js/issues/540 |
* Update to prevent #55 from occurring again This change in the readme is to help future developers not have binary issues across lambda functions created by the next build command. * Include default option and a binary option
Thank you for the fix @garrypolley @FinnWoelm |
I've been following this example and it works on "standard netlify" : https://github.com/garrypolley/deployment-example-netlify
I'm attempting to use next as well on a private site
API ID: c076fc19-1890-4dd6-b610-1b57342b8c39
Whenever any attempt to query the database is made I get the following error:
I believe this is because the rhel binary is not shipping inside the bundled function that goes in the
out_functions
directory.I've tried a lot of options:
I think if the rhel binary can be found on the running lambda disk then this environment variable could be set and it'd work
PRISMA_QUERY_ENGINE_BINARY
There are a few issues logged for this across Netlify and Primsa githubs. And also a community post as well https://community.netlify.com/t/prisma-client-binary-not-copied-for-netlify-lambda-functions-for-graphql-server/11701
I'm happy to help troubleshoot further.
The text was updated successfully, but these errors were encountered: