vercel / next-learn

Learn Next.js Starter Code
https://next-learn-dashboard.vercel.sh/
MIT License
3.77k stars 1.92k forks source link

Chapter 6 'npm run seed' doesn't work #542

Open xiaoqufengdi opened 10 months ago

xiaoqufengdi commented 10 months ago

when I execute 'npm run seed', throw a error. ver

seed

node -r dotenv/config ./scripts/seed.js

An error occurred while attempting to seed the database: VercelPostgresError: VercelPostgresError - 'missing_connection_string ': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found. at createPool (E:\remote\temp\next-learn\dashboard\starter-example\node_modules.store\@vercel+postgres@0.5.1\node_modules \@vercel\postgres\dist\chunk-PKSWROYW.cjs:158:11) at Object.get (E:\remote\temp\next-learn\dashboard\starter-example\node_modules.store\@vercel+postgres@0.5.1\node_modules \@vercel\postgres\dist\chunk-PKSWROYW.cjs:201:16) at main (E:\remote\temp\next-learn\dashboard\starter-example\scripts\seed.js:164:27) at Object. (E:\remote\temp\next-learn\dashboard\starter-example\scripts\seed.js:174:1) at Module._compile (node:internal/modules/cjs/loader:1218:14) at Module._extensions..js (node:internal/modules/cjs/loader:1272:10) at Module.load (node:internal/modules/cjs/loader:1081:32) at Module._load (node:internal/modules/cjs/loader:922:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12) at node:internal/main/run_main_module:23:47 { code: 'missing_connection_string' }

minthu2019 commented 10 months ago

same error bro How can I make it

ryuushihou commented 10 months ago

@minthu2019 @xiaoqufengdi I think there needs to be an equal sign between the attribute and the value. like this

image
xiaoqufengdi commented 10 months ago

Ok, I'm understand.

delbaoliveira commented 10 months ago

Hey @xiaoqufengdi, were you able to find a solution?

xiaoqufengdi commented 10 months ago

@delbaoliveira Yes, you see the picture vercel1

normalscene commented 8 months ago

There is some issue that the seed command doesn't work. I have ensured that the db url is valid one and is online. nslookup confirmed the availability of the db url.

Here is the error:

`saturn@rings:~/mystuff/html/nextjs-dashboard$ npm run seed

seed node -r dotenv/config ./scripts/seed.js

node:events:489 throw er; // Unhandled 'error' event ^

Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout at new NodeError (node:internal/errors:399:5) at internalConnectMultiple (node:net:1099:20) at Timeout.internalConnectMultipleTimeout (node:net:1638: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 (/home/saturn/mystuff/html/nextjs-dashboard/node_modules/ws/lib/websocket.js:1016:13) at ClientRequest. (/home/saturn/mystuff/html/nextjs-dashboard/node_modules/ws/lib/websocket.js:864:5) at ClientRequest.emit (node:events:511:28) at TLSSocket.socketErrorListener (node:_http_client:495:9) at TLSSocket.emit (node:events:511:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { code: 'ERR_SOCKET_CONNECTION_TIMEOUT' }

Node.js v20.2.0 saturn@rings:~/mystuff/html/nextjs-dashboard$ `

here is the nslookup command output:

` saturn@rings:~/mystuff/html/nextjs-dashboard$ nslookup ep-crimson-band-a4lpfsvn-pooler.us-east-1.aws.neon.tech Server: 8.8.8.8 Address: 8.8.8.8#53

Non-authoritative answer: ep-crimson-band-a4lpfsvn-pooler.us-east-1.aws.neon.tech canonical name = us-east-1.aws.neon.tech. Name: us-east-1.aws.neon.tech Address: 23.23.229.9 Name: us-east-1.aws.neon.tech Address: 44.207.148.149 Name: us-east-1.aws.neon.tech Address: 100.26.116.133 Name: us-east-1.aws.neon.tech Address: 52.20.107.131 Name: us-east-1.aws.neon.tech Address: 34.194.100.28 Name: us-east-1.aws.neon.tech Address: 44.199.59.172

saturn@rings:~/mystuff/html/nextjs-dashboard$ `

Any idea what could be wrong ?

normalscene commented 8 months ago

There is some issue that the seed command doesn't work. I have ensured that the db url is valid one and is online. nslookup confirmed the availability of the db url.

Here is the error:

`saturn@rings:~/mystuff/html/nextjs-dashboard$ npm run seed

seed node -r dotenv/config ./scripts/seed.js

node:events:489 throw er; // Unhandled 'error' event ^

Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout at new NodeError (node:internal/errors:399:5) at internalConnectMultiple (node:net:1099:20) at Timeout.internalConnectMultipleTimeout (node:net:1638: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 (/home/saturn/mystuff/html/nextjs-dashboard/node_modules/ws/lib/websocket.js:1016:13) at ClientRequest. (/home/saturn/mystuff/html/nextjs-dashboard/node_modules/ws/lib/websocket.js:864:5) at ClientRequest.emit (node:events:511:28) at TLSSocket.socketErrorListener (node:_http_client:495:9) at TLSSocket.emit (node:events:511:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { code: 'ERR_SOCKET_CONNECTION_TIMEOUT' }

Node.js v20.2.0 saturn@rings:~/mystuff/html/nextjs-dashboard$ `

here is the nslookup command output:

` saturn@rings:~/mystuff/html/nextjs-dashboard$ nslookup ep-crimson-band-a4lpfsvn-pooler.us-east-1.aws.neon.tech Server: 8.8.8.8 Address: 8.8.8.8#53

Non-authoritative answer: ep-crimson-band-a4lpfsvn-pooler.us-east-1.aws.neon.tech canonical name = us-east-1.aws.neon.tech. Name: us-east-1.aws.neon.tech Address: 23.23.229.9 Name: us-east-1.aws.neon.tech Address: 44.207.148.149 Name: us-east-1.aws.neon.tech Address: 100.26.116.133 Name: us-east-1.aws.neon.tech Address: 52.20.107.131 Name: us-east-1.aws.neon.tech Address: 34.194.100.28 Name: us-east-1.aws.neon.tech Address: 44.199.59.172

saturn@rings:~/mystuff/html/nextjs-dashboard$ `

Any idea what could be wrong ?

after 2 hours of R&D, i found that the particular node version has some issue that it causes failure for some unknown reasons which I did not bother my self to investigate as that is not my goal.

Bottom line: if you are using version and encounter a socket connection time out error .. then just upgrade node version and the seeding script will run just fine. thanks.


saturn@rings:~/mystuff/html/nextjs-dashboard$ node -r dotenv/config ./scripts/seed.js
node:events:489
      throw er; // Unhandled 'error' event
      ^

Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout
    at new NodeError (node:internal/errors:399:5)
    at internalConnectMultiple (node:net:1099:20)
    at Timeout.internalConnectMultipleTimeout (node:net:1638: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 (/home/saturn/mystuff/html/nextjs-dashboard/node_modules/ws/lib/websocket.js:1016:13)
    at ClientRequest.<anonymous> (/home/saturn/mystuff/html/nextjs-dashboard/node_modules/ws/lib/websocket.js:864:5)
    at ClientRequest.emit (node:events:511:28)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
    at TLSSocket.emit (node:events:511:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ERR_SOCKET_CONNECTION_TIMEOUT'
}

Node.js v20.2.0
saturn@rings:~/mystuff/html/nextjs-dashboard$ node -v
spreet6999 commented 7 months ago

I am facing the same issue as @xiaoqufengdi:

Here is how my seed.js looks like:

const { db } = require('@vercel/postgres');
const {
 invoices,
 customers,
 revenue,
 users,
} = require('../app/lib/placeholder-data.js');
const bcrypt = require('bcrypt');

async function seedUsers(client) {
 try {
  await client.sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`;
  // Create the "users" table if it doesn't exist
  const createTable = await client.sql`
   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
   );
  `;

  console.log(`Created "users" table`);

  // Insert data into the "users" table
  const insertedUsers = await Promise.all(
   users.map(async (user) => {
    const hashedPassword = await bcrypt.hash(user.password, 10);
    return client.sql`
    INSERT INTO users (id, name, email, password)
    VALUES (${user.id}, ${user.name}, ${user.email}, ${hashedPassword})
    ON CONFLICT (id) DO NOTHING;
   `;
   }),
  );

  console.log(`Seeded ${insertedUsers.length} users`);

  return {
   createTable,
   users: insertedUsers,
  };
 } catch (error) {
  console.error('Error seeding users:', error);
  throw error;
 }
}

async function seedInvoices(client) {
 try {
  await client.sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`;

  // Create the "invoices" table if it doesn't exist
  const createTable = await client.sql`
  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
 );
`;

  console.log(`Created "invoices" table`);

  // Insert data into the "invoices" table
  const insertedInvoices = await Promise.all(
   invoices.map(
    (invoice) => client.sql`
    INSERT INTO invoices (customer_id, amount, status, date)
    VALUES (${invoice.customer_id}, ${invoice.amount}, ${invoice.status}, ${invoice.date})
    ON CONFLICT (id) DO NOTHING;
   `,
   ),
  );

  console.log(`Seeded ${insertedInvoices.length} invoices`);

  return {
   createTable,
   invoices: insertedInvoices,
  };
 } catch (error) {
  console.error('Error seeding invoices:', error);
  throw error;
 }
}

async function seedCustomers(client) {
 try {
  await client.sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`;

  // Create the "customers" table if it doesn't exist
  const createTable = await client.sql`
   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
   );
  `;

  console.log(`Created "customers" table`);

  // Insert data into the "customers" table
  const insertedCustomers = await Promise.all(
   customers.map(
    (customer) => client.sql`
    INSERT INTO customers (id, name, email, image_url)
    VALUES (${customer.id}, ${customer.name}, ${customer.email}, ${customer.image_url})
    ON CONFLICT (id) DO NOTHING;
   `,
   ),
  );

  console.log(`Seeded ${insertedCustomers.length} customers`);

  return {
   createTable,
   customers: insertedCustomers,
  };
 } catch (error) {
  console.error('Error seeding customers:', error);
  throw error;
 }
}

async function seedRevenue(client) {
 try {
  // Create the "revenue" table if it doesn't exist
  const createTable = await client.sql`
   CREATE TABLE IF NOT EXISTS revenue (
    month VARCHAR(4) NOT NULL UNIQUE,
    revenue INT NOT NULL
   );
  `;

  console.log(`Created "revenue" table`);

  // Insert data into the "revenue" table
  const insertedRevenue = await Promise.all(
   revenue.map(
    (rev) => client.sql`
    INSERT INTO revenue (month, revenue)
    VALUES (${rev.month}, ${rev.revenue})
    ON CONFLICT (month) DO NOTHING;
   `,
   ),
  );

  console.log(`Seeded ${insertedRevenue.length} revenue`);

  return {
   createTable,
   revenue: insertedRevenue,
  };
 } catch (error) {
  console.error('Error seeding revenue:', error);
  throw error;
 }
}

async function main() {
 const client = await db.connect();

 await seedUsers(client);
 await seedCustomers(client);
 await seedInvoices(client);
 await seedRevenue(client);

 await client.end();
}

main().catch((err) => {
 console.error(
  'An error occurred while attempting to seed the database:',
  err,
 );
});

Here is how my .env file looks like:

POSTGRES_VERCEL_DB_URL="<placeholder>"
POSTGRES_VERCEL_DB_PRISMA_URL="<placeholder>"
POSTGRES_VERCEL_DB_URL_NO_SSL="<placeholder>"
POSTGRES_VERCEL_DB_URL_NON_POOLING="<placeholder>"
POSTGRES_VERCEL_DB_USER="<placeholder>"
POSTGRES_VERCEL_DB_HOST="<placeholder>"
POSTGRES_VERCEL_DB_PASSWORD="<placeholder>"
POSTGRES_VERCEL_DB_DATABASE="<placeholder>"

AUTH_SECRET=""
AUTH_URL=http://localhost:3000/api/auth

Please look at screenshot attached for error info
Screenshot 2024-03-25 at 18 19 02
belloshehu commented 7 months ago

I got this error:


node:internal/modules/cjs/loader:1147
  throw err;
  ^

Error: Cannot find module 'C:\Users\bello\Development\nextjs-dashboard\node_modules\bcrypt\lib\binding\napi-v3\bcrypt_lib.node'
Require stack:
- C:\Users\bello\Development\nextjs-dashboard\node_modules\bcrypt\bcrypt.js
- C:\Users\bello\Development\nextjs-dashboard\scripts\seed.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (C:\Users\bello\Development\nextjs-dashboard\node_modules\bcrypt\bcrypt.js:6:16)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\bello\\Development\\nextjs-dashboard\\node_modules\\bcrypt\\bcrypt.js',
    'C:\\Users\\bello\\Development\\nextjs-dashboard\\scripts\\seed.js'
  ]
}

Node.js v20.11.0
madamis commented 7 months ago

Am getting this

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:1710: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/mada/next/nextjs-dashboard/node_modules/ws/lib/websocket.js:1016:13) at ClientRequest. (/home/mada/next/nextjs-dashboard/node_modules/ws/lib/websocket.js:864:5) at ClientRequest.emit (node:events:519:28) at TLSSocket.socketErrorListener (node:_http_client:500:9) at TLSSocket.emit (node:events:519:28) at emitErrorNT (node:internal/streams/destroy:169:8) at emitErrorCloseNT (node:internal/streams/destroy:128:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { code: 'ETIMEDOUT',

Error: connect ETIMEDOUT 52.20.107.131:443
    at createConnectionError (node:net:1646:14)
    at Timeout.internalConnectMultipleTimeout (node:net:1705:38)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -110,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '52.20.107.131',
  port: 443
},
Error: connect ENETUNREACH 2600:1f18:240c:5419:4ecf:2a7c:cf52:31ae:443 - Local (:::0)
    at internalConnectMultiple (node:net:1180:16)
    at Timeout.internalConnectMultipleTimeout (node:net:1710:5)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -101,
  code: 'ENETUNREACH',
  syscall: 'connect',
  address: '2600:1f18:240c:5419:4ecf:2a7c:cf52:31ae',
  port: 443
},
Error: connect ETIMEDOUT 44.207.148.149:443
    at createConnectionError (node:net:1646:14)
    at Timeout.internalConnectMultipleTimeout (node:net:1705:38)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -110,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '44.207.148.149',
  port: 443
},
Error: connect ENETUNREACH 2600:1f18:240c:544d:621b:957c:81:5e5b:443 - Local (:::0)
    at internalConnectMultiple (node:net:1180:16)
    at Timeout.internalConnectMultipleTimeout (node:net:1710:5)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -101,
  code: 'ENETUNREACH',
  syscall: 'connect',
  address: '2600:1f18:240c:544d:621b:957c:81:5e5b',
  port: 443
},
Error: connect ETIMEDOUT 23.23.229.9:443
    at createConnectionError (node:net:1646:14)
    at Timeout.internalConnectMultipleTimeout (node:net:1705:38)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -110,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '23.23.229.9',
  port: 443
},
Error: connect ENETUNREACH 2600:1f18:240c:540b:c14a:4d57:1251:234d:443 - Local (:::0)
    at internalConnectMultiple (node:net:1180:16)
    at Timeout.internalConnectMultipleTimeout (node:net:1710:5)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -101,
  code: 'ENETUNREACH',
  syscall: 'connect',
  address: '2600:1f18:240c:540b:c14a:4d57:1251:234d',
  port: 443
},
Error: connect ETIMEDOUT 44.199.59.172:443
    at createConnectionError (node:net:1646:14)
    at Timeout.internalConnectMultipleTimeout (node:net:1705:38)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -110,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '44.199.59.172',
  port: 443
},
Error: connect ENETUNREACH 2600:1f18:240c:5421:acd1:6284:5a8a:d6e9:443 - Local (:::0)
    at internalConnectMultiple (node:net:1180:16)
    at Timeout.internalConnectMultipleTimeout (node:net:1710:5)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -101,
  code: 'ENETUNREACH',
  syscall: 'connect',
  address: '2600:1f18:240c:5421:acd1:6284:5a8a:d6e9',
  port: 443
},
Error: connect ETIMEDOUT 100.26.116.133:443
    at createConnectionError (node:net:1646:14)
    at Timeout.internalConnectMultipleTimeout (node:net:1705:38)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -110,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '100.26.116.133',
  port: 443
},
Error: connect ENETUNREACH 2600:1f18:240c:5454:82a4:8209:20f8:a5c1:443 - Local (:::0)
    at internalConnectMultiple (node:net:1180:16)
    at Timeout.internalConnectMultipleTimeout (node:net:1710:5)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -101,
  code: 'ENETUNREACH',
  syscall: 'connect',
  address: '2600:1f18:240c:5454:82a4:8209:20f8:a5c1',
  port: 443
},
Error: connect ETIMEDOUT 34.194.100.28:443
    at createConnectionError (node:net:1646:14)
    at Timeout.internalConnectMultipleTimeout (node:net:1705:38)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -110,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '34.194.100.28',
  port: 443
},
Error: connect ENETUNREACH 2600:1f18:240c:543b:a8aa:14fb:d008:11fe:443 - Local (:::0)
    at internalConnectMultiple (node:net:1180:16)
    at Timeout.internalConnectMultipleTimeout (node:net:1710:5)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -101,
  code: 'ENETUNREACH',
  syscall: 'connect',
  address: '2600:1f18:240c:543b:a8aa:14fb:d008:11fe',
  port: 443
}

] }

Node.js v21.7.1

madamis commented 7 months ago

I switched to this node version and it worked. Now using node v18.20.0 (npm v10.5.0)

fath-nasrudin commented 7 months ago

I switched to this node version and it worked. Now using node v18.20.0 (npm v10.5.0)

It works for me. Thanks madamis!

Murimi79 commented 7 months ago

I switched to this node version and it worked. Now using node v18.20.0 (npm v10.5.0)

Worked for me too. Thanks madamis. 😊

muhtasimhafiz commented 6 months ago

I switched to this node version and it worked. Now using node v18.20.0 (npm v10.5.0)

thanks man

vanthinh01052001 commented 6 months ago

I switched to this node version and it worked. Now using node v18.20.0 (npm v10.5.0)

thanks, it ran

vrashabh-k commented 6 months ago

I switched to this node version and it worked. Now using node v18.20.0 (npm v10.5.0)

Thanks man, it worked

seanchuatech commented 5 months ago

I switched to this node version and it worked. Now using node v18.20.0 (npm v10.5.0)

This works for me. :) Thank you!

DAN-BIWOTT commented 5 months ago

I switched to this node version and it worked. Now using node v18.20.0 (npm v10.5.0)

Arigatou, Big-man. You just saved a life.

abdulrehman3725 commented 4 months ago

I tried my node to v18.20.0 but did not worked

I guess they have updated this

Now I have updated to the v21 and it worked like a charm