skip to Main Content

Happy Monday! I’ve recently run into a weird issue and can’t seem to figure out what would be causing it.

I have a NextJS project using Prisma and Supabase. When I run the app on my Windows desktop or Vercel, it runs perfectly with no error. However, when I run it on my MacBook, it presents me with this error:

Error: 
Invalid `prisma.user.findUnique()` invocation:


Can't reach database server at `aws-0-us-east-1.pooler.supabase.com`:`5432`

Please make sure your database server is running at `aws-0-us-east-1.pooler.supabase.com`:`5432`.
Source
src/app/layout.tsx (37:17) @ async getData
  35 | noStore();
  36 | if (userId) {
> 37 |   const data = await prisma.user.findUnique({
     |               ^
  38 |     where: {
  39 |       id: userId,
  40 |     },

I’ve looked around for some answers but can’t seem to find anyone with the same problem, any help would be appreciated!

2

Answers


  1. Get Transaction and Session connection pooler string from your Superbase database setting page.

    Transaction connection pooler string:

    postgres://[db-user].[project-ref]:[db-password]@aws-0-[aws-region].pooler.supabase.com:6543/[db-name]?pgbouncer=true&connection_limit=1
    

    Session connection pooler string:

    postgres://[db-user].[project-ref]:[db-password]@aws-0-[aws-region].pooler.supabase.com:5432/[db-name]
    

    Update .env file:

    DATABASE_URL="" #The Transaction connection pooler string
    DIRECT_URL=""  #The Session connection pooler string
    

    schema.prisma file should look like:

    datasource db {
     provider          = "postgresql"
     url               = env("DATABASE_URL")
     directUrl         = env("DIRECT_URL")
    }
    

    From Superbase document

    Login or Signup to reply.
  2. A solution that worked for me in the connection string for directUrl = env("DIRECT_DATABASE_URL").

    -DIRECT_DATABASE_URL=postgres://postgres:[YOUR-PASSWORD]@db.[project-ref].supabase.co:5432/postgres
    +DIRECT_DATABASE_URL=postgres://postgres.[project-ref]:[YOUR-PASSWORD]@aws-0-eu-central-1.pooler.supabase.com:5432/postgres
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search