next-learn icon indicating copy to clipboard operation
next-learn copied to clipboard

Chapter 6: Setting up your database - Error [object Object]

Open matt-halden opened this issue 1 year ago • 9 comments

Hi, I am on my second round of doing this next.js tutorial from scratch in an attempt to seed the postgres database correctly, but I just cannot figure out why I am non de-script errors (Error: [object Object]), even when on my first try I tried to log everything on my first go around. Please help!

I am pasting a screenshot of my browser errors and linking my current repo if anyone is willing to take a look. I read many other posts on chapter 6 errors, correctly commented out my route.ts ("uncomment this file..."), compared with a friend who got it working (but, looks like his route.ts file was different from a few months ago), see no logs anywhere in Vercel, etc. I confirm I correctly pasted over the env variables into my .env file. I got an error trying to install bcryptjs to see if that was somehow the error that Vercel recommends to check. Let me know if there is anything I can try, I am very confused.

Screenshot 2024-08-14 at 9 33 17 AM

Repo: https://github.com/pyMasta/nextjs-v3

matt-halden avatar Aug 14 '24 16:08 matt-halden

Well, it looks like somebody else had the same error that i miss, and it works if you run /seed on your deployed environment, not local like the instructions have: https://github.com/vercel/next-learn/issues/792

However, I am not sure if this is the way Vercel does want you to do this or if they just have not updated the tutorial.

matt-halden avatar Aug 14 '24 17:08 matt-halden

I get the exact same error. This is my fourth rerun of the project tutorial 😓

SiyabongaMat avatar Aug 14 '24 18:08 SiyabongaMat

I hear you. I just got it working, saw the data, and now Vercel errors saying "Failed to fetch tables in your database" and the data is gone :/

matt-halden avatar Aug 14 '24 18:08 matt-halden

Does the error say: 'error fetching card data' and shows that the error is in the fetchInvoices method?

SiyabongaMat avatar Aug 14 '24 18:08 SiyabongaMat

I figured something out. It worked finally. What I did: I changed the region of the postgres database to frankfurt germany. It is more in line with my timezone. Also, there is a step that I missed. Its so small its easy to miss it. Just after telling you to create a postgres database and connecting it to you project it subtly tells you to install the vercel/postgres sdk with this line:

Finally, run pnpm i @vercel/postgres in your terminal to install the Vercel Postgres SDK

In my other attempts, when I checked my package.json file for dependancies, I always thought there was no need to install the vercel/postgres sdk because I thought it was already installed, but turns out you need to install the sdk.

Hope this helps 😁👍

SiyabongaMat avatar Aug 15 '24 08:08 SiyabongaMat

@SiyabongaMat Hey, glad to hear that you resolved issue on your own. I think it should be removed.

akkshayTandon avatar Aug 21 '24 20:08 akkshayTandon

I figured something out. It worked finally. What I did: I changed the region of the postgres database to frankfurt germany. It is more in line with my timezone. Also, there is a step that I missed. Its so small its easy to miss it. Just after telling you to create a postgres database and connecting it to you project it subtly tells you to install the vercel/postgres sdk with this line:

Finally, run pnpm i @vercel/postgres in your terminal to install the Vercel Postgres SDK

In my other attempts, when I checked my package.json file for dependancies, I always thought there was no need to install the vercel/postgres sdk because I thought it was already installed, but turns out you need to install the sdk.

Hope this helps 😁👍

Hi, I was wondering if you ended up successfully seeding locally?I'm having this problem: I can successfully seed an application that I deployed on vercel, but it keeps failing to seed locally, maybe vercel doesn't support local connections to vercel/postgres?

KinonoChen avatar Aug 29 '24 17:08 KinonoChen

@KinonoChen Instead of using @vercel/postgres, I used the node-postgres package and rewrote the seed file to use its syntax. The changes were fairly minimal. This allowed me to connect to a Postgres database running on my machine in Docker for testing. Hope this helps.

BrettHoyer avatar Sep 26 '24 04:09 BrettHoyer

The issue as far as I can tell is that the Washington default server causes a latency that lags out the request. If you are using the "@vercel/postgres" package to connect to their cloud database, it might work better if you delete the database, re-create the database, and select a server close to your geographic location.

One of the ways I confirmed this was the issue:

  • used the cloud deployed site with the /seed endpoint, this successfully seeded the database (Washington server)
  • created a new database with a geographically close server to me, this also worked from the deployed /seed endpoint (Closer server)
  • the new database also worked locally when using the local /seed endpoint (Closer server)

Without looking into the specific code that is a part of the Vercel postgres package, I am going to assume that the request is timing out (read: unresolved promise) due to geographic location. This issue should be fixed if someone from Vercel ever has 20 minutes to fix this.

SteaneMurphy avatar Oct 27 '24 07:10 SteaneMurphy

https://github.com/vercel/next-learn/issues/868

leerob avatar Jan 27 '25 14:01 leerob

please i got the same issue and i can't change the region and i already have vercel/postgres sdk installed but still i can't seed the database

ChrinaerDev avatar Apr 29 '25 23:04 ChrinaerDev