N
Neonβ€’2y ago
ambitious-aqua

NeonDbError: Error connecting to database: fetch failed

Hi team, I was using Drizzle to migrate the database from the preview branch that was integrated with Vercel, but I got that error. Here are the code snippets: migrate.ts
import { neon } from '@neondatabase/serverless';
import { config } from 'dotenv';
import { drizzle } from 'drizzle-orm/neon-http';
import { migrate } from 'drizzle-orm/neon-http/migrator';

config({ path: '.env.local' });

const sql = neon(process.env.DATABASE_URL!);
const db = drizzle(sql);

const main = async () => {
try {
console.log('🚧 Migrating database');
await migrate(db, { migrationsFolder: 'src/lib/server/db/migrations' });
console.log('βœ… Migration completed');
} catch (error) {
console.error('🚨 Error during migration:', error);
process.exit(1);
}
};

main();
import { neon } from '@neondatabase/serverless';
import { config } from 'dotenv';
import { drizzle } from 'drizzle-orm/neon-http';
import { migrate } from 'drizzle-orm/neon-http/migrator';

config({ path: '.env.local' });

const sql = neon(process.env.DATABASE_URL!);
const db = drizzle(sql);

const main = async () => {
try {
console.log('🚧 Migrating database');
await migrate(db, { migrationsFolder: 'src/lib/server/db/migrations' });
console.log('βœ… Migration completed');
} catch (error) {
console.error('🚨 Error during migration:', error);
process.exit(1);
}
};

main();
package.json
{
"scripts": {
"db:generate": "drizzle-kit generate:pg --schema src/lib/server/db/schema.ts --out src/lib/server/db/migrations",
"db:migrate": "tsx src/lib/server/db/migrate.ts",
}
"devDependencies": {
"drizzle-kit": "^0.20.16",
}
"dependencies": {
"@neondatabase/serverless": "^0.9.1",
"drizzle-orm": "^0.30.8",
}
}
{
"scripts": {
"db:generate": "drizzle-kit generate:pg --schema src/lib/server/db/schema.ts --out src/lib/server/db/migrations",
"db:migrate": "tsx src/lib/server/db/migrate.ts",
}
"devDependencies": {
"drizzle-kit": "^0.20.16",
}
"dependencies": {
"@neondatabase/serverless": "^0.9.1",
"drizzle-orm": "^0.30.8",
}
}
Any kind of help would be appreciated πŸ™‚
26 Replies
stormy-gold
stormy-goldβ€’2y ago
Any additional error information? Can you share your DATABASE_URL value (remove the password before sending it)
ambitious-aqua
ambitious-aquaOPβ€’2y ago
Hey @Conrad Ludgate , there you go: DATABASE_URL="postgres://feedbackpaw_owner:xxx@ep-long-paper-a5w2o9e3-pooler.us-east-2.aws.neon.tech/feedbackpaw?sslmode=require" Some additional errors are attached.
No description
stormy-gold
stormy-goldβ€’2y ago
ah, the illusive ETIMEDOUT error again. this one is very perculiar Can you try https://discord.com/channels/1176467419317940276/1176467419938701375/1217607005661827293
ambitious-aqua
ambitious-aquaOPβ€’2y ago
I’m away from the keyboard right now, but I’ll try it soon. Coincidentally, I’m using Node 20 here, which will be the main issue according to the chat that you referenced. Let’s see then…
stormy-gold
stormy-goldβ€’2y ago
Also, are you located in the US or outside? I wonder if node's default TCP timeout is set quite low
ambitious-aqua
ambitious-aquaOPβ€’2y ago
Not in the US at the moment. Do you have any recommendations to adjust the timeout?
stormy-gold
stormy-goldβ€’2y ago
Stack Overflow
What could cause "connect ETIMEDOUT" error when the URL is working ...
I train myslef with NodeJS and tried a simple GET call. Here is my code: var http = require('http'); var options = { host: 'www.boardgamegeek.com', path: '/xmlapi/boardgame/1?stats=1',
Stack Overflow
Socket connection timout error in Node js
I've been having trouble uploading images to cloudinary in Node JS because when I try to I get this error Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout { error: Error [
Stack Overflow
Socket connection timout error in Node js
I've been having trouble uploading images to cloudinary in Node JS because when I try to I get this error Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout { error: Error [
stormy-gold
stormy-goldβ€’2y ago
I'm struggling to find the config to set the timeout :/ Node docs are not the greatest
helpful-purple
helpful-purpleβ€’2y ago
Interesting that Node.js 20 is correlated. Is that when they switched the fetch implementation to Undici?
ambitious-aqua
ambitious-aquaOPβ€’2y ago
So I downgraded the Node version to 18.20.2 and it works. Thanks, Conrad πŸ™‚
stormy-gold
stormy-goldβ€’2y ago
I think we need to add node 20 to our internal test suite. It's rather unfortunate that this is happening
helpful-purple
helpful-purpleβ€’2y ago
Yeah, something funky is going on with DNS or fetch. IIRC I tested with another user via DM and timeouts were occurring before fetch was invoked, like the timeout was β€œrandomly” thrown between 700-1000ms of calling neon
other-emerald
other-emeraldβ€’2y ago
I'm having trouble in connecting the db Can anyone help me with that?
xenial-black
xenial-blackβ€’2y ago
what is the issue?
other-emerald
other-emeraldβ€’2y ago
This is my drizzle.config.ts file import type { Config } from "drizzle-kit"; export default { schema: "src/db/schema.ts", out: "src/drizzle", driver: "pg", dbCredentials: { connectionString: process.env.NEON_DB_URL! as string, }, schemaFilter: ["public"], } satisfies Config;
other-emerald
other-emeraldβ€’2y ago
No description
other-emerald
other-emeraldβ€’2y ago
I'm making a todo app to get hands on with this tech, but found this error which is like bothering me so much.
xenial-black
xenial-blackβ€’2y ago
which node version are you on 20?
other-emerald
other-emeraldβ€’2y ago
18.20.2
helpful-purple
helpful-purpleβ€’2y ago
Can you post the full error text instead of a screenshot? Also, are you using WSL? Seems WSL has networking limitations: https://discord.com/channels/1176467419317940276/1176467419938701375/1233168994584756296
other-emerald
other-emeraldβ€’2y ago
this is the error:
other-emerald
other-emeraldβ€’2y ago
This is the GET API export const GET = async (req: NextRequest, res: NextResponse) => { // try { console.log("first call"); const dbData = await db.select().from(todo);
return NextResponse.json({ message: "Get Successfull req", data: dbData }); // } catch (error) { // return NextResponse.json({ message: "Error getting next request" }); // } };
helpful-purple
helpful-purpleβ€’2y ago
Are you using WSL? What is the output of console.log(process.version). I think you might be using Node.js v20 since the error message mentioned Undici and some users have had issues with Node.js v20 that we have yet to explore: node:internal/deps/undici/undici:12442:11 Oh my mistake. It seems Undici is in Node.js v18 also. Are you able to connect using psql from a terminal? Another thing you can try (if psql works), start a Node.js process that uses the Neon driver with --no-experimental-fetch , e.g node neon-test.js --no-experimental-fetch and see if that works
fair-rose
fair-roseβ€’2y ago
Is there a known issues page somewhere? Relatedly, is the recommendation to stay on node 18? I'm in the process of updating to 20 but saw this thread.
helpful-purple
helpful-purpleβ€’2y ago
We have an issue tracker on GitHub @san4d https://github.com/neondatabase/serverless/issues/76 Are you seeing the same behaviour?
GitHub
Transactions not working in Node 20 Β· Issue #76 Β· neondatabase/serv...
I previously had no issues until I tried to upgrade from node 18.19.1 to 20.12.2. When making a parallel insert in a transaction, it seems to lose sight of the transaction scope when using neon ser...
fair-rose
fair-roseβ€’2y ago
Not yet. I'll update that thread if there's an issue

Did you find this page helpful?