next-learn
next-learn copied to clipboard
Cannot run seed.js
After I run npm run seed, here is the error message,
seed node -r dotenv/config ./scripts/seed.js
node:events:492 throw er; // Unhandled 'error' event ^
Error: getaddrinfo ENOTFOUND ep-plain-union-a7292e8g-pooler.ap-southeast-2.postgres.vercel-storage.com
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26)
Emitted 'error' event on WebSocket instance at:
at emitErrorAndClose (/Users/roy/Documents/Code/nextjs-dashboard/node_modules/ws/lib/websocket.js:1016:13)
at ClientRequest.
Node.js v20.10.0
Could anyone help?
The error message you're encountering, Error: getaddrinfo ENOTFOUND, typically indicates a problem with DNS resolution, meaning the Node.js application is unable to resolve the hostname of your PostgreSQL database to an IP address. The hostname in question here appears to be related to a database service, possibly provided by Vercel, and the error suggests that the Node.js process can't find or connect to the specified database server.
Here are several steps you can take to troubleshoot and hopefully resolve this issue:
- Verify Database Hostname Double-check that the hostname ep-plain-union-a7292e8g-pooler.ap-southeast-2.postgres.vercel-storage.com is correct. It's possible there could be a typo in your .env file or wherever your database configuration is specified.
- Check .env File and Environment Variables Ensure your .env file (or other configuration files) is correctly set up and located in the right directory from where you're running the npm run seed command. The dotenv library loads environment variables from this file. Verify that the environment variable for your database URL (often something like DATABASE_URL) matches the expected format and uses the correct hostname.
- Test DNS Resolution Try to resolve the DNS name manually using tools like ping or nslookup from your terminal or command prompt to ensure that the hostname can be resolved to an IP address from your network.
bash Copy code nslookup ep-plain-union-a7292e8g-pooler.ap-southeast-2.postgres.vercel-storage.com If the DNS resolution fails, there might be a network issue, or the hostname might not be correctly configured in the DNS.
- Internet Connection and VPN/Proxy Settings Ensure that your internet connection is stable and that you're not behind a VPN or proxy that might interfere with DNS resolution or block connections to the database server.
- Firewall and Security Group Settings If you're running this in an environment with a firewall or cloud security groups (e.g., AWS, Google Cloud, Azure), make sure that outgoing connections to the PostgreSQL server on the required port (usually 5432) are allowed.
- Contact Database Host or Support If you've confirmed the hostname is correct and you're still facing issues, there might be a problem with the database service itself. Contact Vercel support or the support team for your database hosting service for further assistance. There could be an issue on their end or additional configuration required for your account.
- Review Database Client Configuration Make sure your database client configuration in the seed.js script (or related database connection logic) correctly uses the environment variables loaded by dotenv. Incorrect configuration could lead to this error if the hostname isn't being correctly passed to the database client. Addressing these points should help identify and resolve the ENOTFOUND error, allowing your seeding script to connect to the PostgreSQL database successfully.
For anyone that gets stuck, try changing .env.local
to .env
. This fixed the issue for me.
node:events:496 throw er; // Unhandled 'error' event ^
AggregateError
at internalConnectMultiple (node:net:1114:18)
at internalConnectMultiple (node:net:1177:5)
at Timeout.internalConnectMultipleTimeout (node:net:1687:3)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7)
Emitted 'error' event on WebSocket instance at:
at emitErrorAndClose (/Users/prateek/Desktop/nextjs/nextjs-dashboard/node_modules/ws/lib/websocket.js:1016:13)
at ClientRequest.
Node.js v20.11.1
Not able to resolve this error.
I encountered the same issue did you find any solution?
Edit: I created another database but with a different region this time and it worked.
try running vercel dev instead of npm run dev
that did the magic for me https://github.com/orgs/vercel/discussions/2350#discussioncomment-5850746
Cannot resolve this env filename is ".env" nslookup us-east-1.aws.neon.tech returned: Name and Address, they were 12 in vercel, the status is available region is Washington, D.C., USA
npm run seed
seed node -r dotenv/config ./scripts/seed.js
node:events:497 throw er; // Unhandled 'error' event ^
AggregateError [ETIMEDOUT]:
at internalConnectMultiple (node:net:1116:18)
at internalConnectMultiple (node:net:1184:5)
at Timeout.internalConnectMultipleTimeout (node:net:1707:5)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7)
Emitted 'error' event on WebSocket instance at:
at emitErrorAndClose (/home/sab/Public/bell/NextJs/nextjs-dashboard/node_modules/ws/lib/websocket.js:1016:13)
at ClientRequest.
Node.js v21.6.2
`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE TABLE IF NOT EXISTS users ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, name VARCHAR(255) NOT NULL, email TEXT NOT NULL UNIQUE, password TEXT NOT NULL );
CREATE TABLE IF NOT EXISTS invoices ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, customer_id UUID NOT NULL, amount INT NOT NULL, status VARCHAR(255) NOT NULL, date DATE NOT NULL );
CREATE TABLE IF NOT EXISTS customers ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, image_url VARCHAR(255) NOT NULL );
CREATE TABLE IF NOT EXISTS revenue ( month VARCHAR(4) NOT NULL UNIQUE, revenue INT NOT NULL );
INSERT INTO customers (id, name, email, image_url) VALUES ('3958dc9e-712f-4377-85e9-fec4b6a6442a', 'Delba de Oliveira', '[email protected]', '/customers/delba-de-oliveira.png'), ('3958dc9e-742f-4377-85e9-fec4b6a6442a', 'Lee Robinson', '[email protected]', '/customers/lee-robinson.png'), ('3958dc9e-737f-4377-85e9-fec4b6a6442a', 'Hector Simpson', '[email protected]', '/customers/hector-simpson.png'), ('50ca3e18-62cd-11ee-8c99-0242ac120002', 'Steven Tey', '[email protected]', '/customers/steven-tey.png'), ('3958dc9e-787f-4377-85e9-fec4b6a6442a', 'Steph Dietz', '[email protected]', '/customers/steph-dietz.png'), ('76d65c26-f784-44a2-ac19-586678f7c2f2', 'Michael Novotny', '[email protected]', '/customers/michael-novotny.png'), ('d6e15727-9fe1-4961-8c5b-ea44a9bd81aa', 'Evil Rabbit', '[email protected]', '/customers/evil-rabbit.png'), ('126eed9c-c90c-4ef6-a4a8-fcf7408d3c66', 'Emil Kowalski', '[email protected]', '/customers/emil-kowalski.png'), ('CC27C14A-0ACF-4F4A-A6C9-D45682C144B9', 'Amy Burns', '[email protected]', '/customers/amy-burns.png'), ('13D07535-C59E-4157-A011-F8D2EF4E0CBB', 'Balazs Orban', '[email protected]', '/customers/balazs-orban.png') ON CONFLICT (id) DO NOTHING;
INSERT INTO invoices (customer_id, amount, status, date) VALUES ('3958dc9e-712f-4377-85e9-fec4b6a6442a', 15795, 'pending', '2022-12-06'), ('3958dc9e-742f-4377-85e9-fec4b6a6442a', 20348, 'pending', '2022-11-14'), ('3958dc9e-787f-4377-85e9-fec4b6a6442a', 3040, 'paid', '2022-10-29'), ('50ca3e18-62cd-11ee-8c99-0242ac120002', 44800, 'paid', '2023-09-10'), ('3958dc9e-787f-4377-85e9-fec4b6a6442a', 34577, 'pending', '2023-08-05'), ('76d65c26-f784-44a2-ac19-586678f7c2f2', 54246, 'pending', '2023-07-16'), ('d6e15727-9fe1-4961-8c5b-ea44a9bd81aa', 666, 'pending', '2023-06-27'), ('50ca3e18-62cd-11ee-8c99-0242ac120002', 32545, 'paid', '2023-06-09'), ('3958dc9e-787f-4377-85e9-fec4b6a6442a', 1250, 'paid', '2023-06-17'), ('76d65c26-f784-44a2-ac19-586678f7c2f2', 8546, 'paid', '2023-06-07'), ('3958dc9e-742f-4377-85e9-fec4b6a6442a', 500, 'paid', '2023-08-19'), ('76d65c26-f784-44a2-ac19-586678f7c2f2', 8945, 'paid', '2023-06-03'), ('3958dc9e-737f-4377-85e9-fec4b6a6442a', 8945, 'paid', '2023-06-18'), ('3958dc9e-712f-4377-85e9-fec4b6a6442a', 8945, 'paid', '2023-10-04'), ('3958dc9e-737f-4377-85e9-fec4b6a6442a', 1000, 'paid', '2022-06-05') ON CONFLICT (id) DO NOTHING;
INSERT INTO revenue (month, revenue) VALUES ('Jan', 2000), ('Feb', 1800), ('Mar', 2200), ('Apr', 2500), ('May', 2300), ('Jun', 3200), ('Jul', 3500), ('Aug', 3700), ('Sep', 2500), ('Oct', 2800), ('Nov', 3000), ('Dec', 4800) ON CONFLICT (month) DO NOTHING;
INSERT INTO users (id, name, email, password) VALUES ('410544b2-4001-4271-9855-fec4b6a6442a', 'User', '[email protected]', '123456'); `
run this one by one in vercel ui then in local use vercel dev to run the app for now forget about the seed part it's not worth debugging
`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE TABLE IF NOT EXISTS users ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, name VARCHAR(255) NOT NULL, email TEXT NOT NULL UNIQUE, password TEXT NOT NULL );
CREATE TABLE IF NOT EXISTS invoices ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, customer_id UUID NOT NULL, amount INT NOT NULL, status VARCHAR(255) NOT NULL, date DATE NOT NULL );
CREATE TABLE IF NOT EXISTS customers ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, image_url VARCHAR(255) NOT NULL );
CREATE TABLE IF NOT EXISTS revenue ( month VARCHAR(4) NOT NULL UNIQUE, revenue INT NOT NULL );
INSERT INTO customers (id, name, email, image_url) VALUES ('3958dc9e-712f-4377-85e9-fec4b6a6442a', 'Delba de Oliveira', '[email protected]', '/customers/delba-de-oliveira.png'), ('3958dc9e-742f-4377-85e9-fec4b6a6442a', 'Lee Robinson', '[email protected]', '/customers/lee-robinson.png'), ('3958dc9e-737f-4377-85e9-fec4b6a6442a', 'Hector Simpson', '[email protected]', '/customers/hector-simpson.png'), ('50ca3e18-62cd-11ee-8c99-0242ac120002', 'Steven Tey', '[email protected]', '/customers/steven-tey.png'), ('3958dc9e-787f-4377-85e9-fec4b6a6442a', 'Steph Dietz', '[email protected]', '/customers/steph-dietz.png'), ('76d65c26-f784-44a2-ac19-586678f7c2f2', 'Michael Novotny', '[email protected]', '/customers/michael-novotny.png'), ('d6e15727-9fe1-4961-8c5b-ea44a9bd81aa', 'Evil Rabbit', '[email protected]', '/customers/evil-rabbit.png'), ('126eed9c-c90c-4ef6-a4a8-fcf7408d3c66', 'Emil Kowalski', '[email protected]', '/customers/emil-kowalski.png'), ('CC27C14A-0ACF-4F4A-A6C9-D45682C144B9', 'Amy Burns', '[email protected]', '/customers/amy-burns.png'), ('13D07535-C59E-4157-A011-F8D2EF4E0CBB', 'Balazs Orban', '[email protected]', '/customers/balazs-orban.png') ON CONFLICT (id) DO NOTHING;
INSERT INTO invoices (customer_id, amount, status, date) VALUES ('3958dc9e-712f-4377-85e9-fec4b6a6442a', 15795, 'pending', '2022-12-06'), ('3958dc9e-742f-4377-85e9-fec4b6a6442a', 20348, 'pending', '2022-11-14'), ('3958dc9e-787f-4377-85e9-fec4b6a6442a', 3040, 'paid', '2022-10-29'), ('50ca3e18-62cd-11ee-8c99-0242ac120002', 44800, 'paid', '2023-09-10'), ('3958dc9e-787f-4377-85e9-fec4b6a6442a', 34577, 'pending', '2023-08-05'), ('76d65c26-f784-44a2-ac19-586678f7c2f2', 54246, 'pending', '2023-07-16'), ('d6e15727-9fe1-4961-8c5b-ea44a9bd81aa', 666, 'pending', '2023-06-27'), ('50ca3e18-62cd-11ee-8c99-0242ac120002', 32545, 'paid', '2023-06-09'), ('3958dc9e-787f-4377-85e9-fec4b6a6442a', 1250, 'paid', '2023-06-17'), ('76d65c26-f784-44a2-ac19-586678f7c2f2', 8546, 'paid', '2023-06-07'), ('3958dc9e-742f-4377-85e9-fec4b6a6442a', 500, 'paid', '2023-08-19'), ('76d65c26-f784-44a2-ac19-586678f7c2f2', 8945, 'paid', '2023-06-03'), ('3958dc9e-737f-4377-85e9-fec4b6a6442a', 8945, 'paid', '2023-06-18'), ('3958dc9e-712f-4377-85e9-fec4b6a6442a', 8945, 'paid', '2023-10-04'), ('3958dc9e-737f-4377-85e9-fec4b6a6442a', 1000, 'paid', '2022-06-05') ON CONFLICT (id) DO NOTHING;
INSERT INTO revenue (month, revenue) VALUES ('Jan', 2000), ('Feb', 1800), ('Mar', 2200), ('Apr', 2500), ('May', 2300), ('Jun', 3200), ('Jul', 3500), ('Aug', 3700), ('Sep', 2500), ('Oct', 2800), ('Nov', 3000), ('Dec', 4800) ON CONFLICT (month) DO NOTHING;
INSERT INTO users (id, name, email, password) VALUES ('410544b2-4001-4271-9855-fec4b6a6442a', 'User', '[email protected]', '123456'); `
Where to add this?
You need execute them in vercel postgres
Go to your project in vercel
You must have created postgres db for your project based on chapter 6.
If you scroll down there you'll see a box and you need click on queries then paste these one by one then execute.
Once all of them are executed you have the db ready.
Now in your local run vercel dev
That should do the work
You need execute them in vercel postgres
Go to your project in vercel
You must have created postgres db for your project based on chapter 6.
If you scroll down there you'll see a box and you need click on queries then paste these one by one then execute.
Once all of them are executed you have the db ready.
Now in your local run vercel dev
That should do the work
It worked!