Next.js Discord

Discord Forum

Intermittent PrismaClientInitializationError in Async Prisma Calls with Next.js and PlanetScale

Unanswered
King Shepherd posted this in #help-forum
Open in Discord
King ShepherdOP
Description:
I'm deploying a Next.js application on Vercel, using PlanetScale as my database and Prisma as the ORM. I'm encountering a blocking issue when making asynchronous calls to Prisma. Specifically, the function getUserIdFromOpenid(openid) is designed to retrieve a user ID based on an openid. However, while invoking this function asynchronously, Prisma intermittently fails with a PrismaClientInitializationError.

Relevant Code:
async function getUserIdFromOpenid(openid) {
  console.log('getUserIdFromOpenid');
  console.log('db', db);
  const account = await db.account.findUnique({
    where: {
      provider_providerAccountId: {
        provider: 'wechat', // Ensure this value exists in the database
        providerAccountId: openid,
      },
    },
  });
  console.log('account');
  console.log(account);
  return account ? account.userId : null;
}


Error Encountered:
- PrismaClientInitializationError occurs intermittently when the getUserIdFromOpenid function is called.

Attempted Solutions:
- Ensured that the provider value 'wechat' exists in the database.
- Checked for any network-related issues with the database connection.

I'm seeking guidance on how to resolve this intermittent PrismaClientInitializationError, possibly related to async operations with Prisma in a Next.js and PlanetScale environment.

0 Replies