PrismaClientInitializationError
Hello! I'm new to posting here. I'm developing the Next.js app and deploying it to AWS Amplify. However, I'm having problems using Prisma and Auth.js. When I use both prima and auth's session, I get a "PrismaClientInitializationError." The local and Vercel hosting cases are working without this issue. Do you have any thoughts?
12 Replies
You opted for speed from this bot. Let's conjure up an answer right now!
Based on the knowledge sources provided, it appears that you're encountering a common issue when deploying a Next.js application with Prisma and Auth.js to AWS Amplify. This problem is specifically related to the initialization of the Prisma Client in the AWS Amplify environment. Let me provide some insights and potential solutions:
1. The error you're seeing, "PrismaClientInitializationError," is often caused by Prisma not being able to find the
schema.prisma
file in the deployed environment. This is a known issue when deploying to AWS Amplify, as discussed in this GitHub issue.
2. The root cause seems to be that AWS Amplify deploys API routes to Lambda functions, where the schema.prisma
file is not present in the expected location.
3. A potential solution that has worked for some users is to modify your next.config.js
file. You can try adding the following webpack configuration:
4. Additionally, you might need to ensure that your schema.prisma
file is properly copied to the deployment environment. However, the exact method to do this in AWS Amplify is not clear from the provided knowledge sources.
5. It's worth noting that this issue doesn't occur on Vercel or in local development, which suggests it's specific to the AWS Amplify deployment process.
6. Some users have reported success by using the experimental-serverless-trace
target in their Next.js configuration, as mentioned in this comment. You could try adding this to your next.config.js
:
Given the complexity of this issue and the lack of a definitive solution in the provided knowledge sources, you might want to consider the following steps:
1. Try implementing the suggested cha
nges to your next.config.js
file.
2. Ensure that your Prisma schema and client are properly generated during the build process on AWS Amplify.
3. Double-check that your environment variables, especially the database connection string, are correctly set in the AWS Amplify environment.
If these steps don't resolve the issue, you may need to reach out to AWS Amplify support or consider alternative deployment options that are known to work well with Prisma and Auth.js, such as Vercel.
š¤ Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.This issue only happens using Auth.js's session.
Sorry, I'm new to using Discord. I'm not sure how to form the code.š©
Hi @Mildseven-Light
Does this happen only on deploy to AWS Amplify? Can you log the output of auth() to ensure it retrieves the session correctly in AWS Amplify's environment.
I deployed the same app to Vercel, and it works fine.
Also, the output of auth() is working correctly.
From the error message, i can see that it says
Can you add
rhel-openssl-1.O.x
to 'binaryTargets' in the schema prisma fileDo you know how to add rhel-openssl-1.O.x?
In your schema.prisma file, you should see this section
I'm deploying right now. Thank you for your help!
You're welocme. Let me know if you run into any more issues
Yes will do!
@RaphaelEtim Thank you so much for your help! It is working now! You made my day!
You're welcome