NeonN
Neon3w ago
12 replies
nursing-lime

Neon + Prisma + Vercel — fetch failed / UND_ERR_SOCKET

Hello, I need urgent help. Since two days ago, my production app started failing to connect to the database after following the Neon + Prisma documentation.

I’m using Vercel with Prisma + Neon (serverless) and I’m getting the following error in production:

❌ Cache function error: Error [NeonDbError]: Error connecting to database: TypeError: fetch failed
cause: Error [SocketError]: other side closed
code: 'UND_ERR_SOCKET'
clientVersion: '7.0.0'

This is my current lib/prisma.ts configuration:
import { PrismaClient } from '@/app/generated/prisma/client';
import { neonConfig } from '@neondatabase/serverless';
import { PrismaNeon } from '@prisma/adapter-neon';
import 'dotenv/config';

import ws from 'ws';
neonConfig.webSocketConstructor = ws;
neonConfig.poolQueryViaFetch = true;

const connectionString = process.env.DATABASE_URL!;
const adapter = new PrismaNeon({ connectionString });

export const prisma =
(global as unknown as { prisma?: PrismaClient }).prisma ??
new PrismaClient({ adapter });

if (process.env.NODE_ENV === 'development') {
(global as unknown as { prisma?: PrismaClient }).prisma = prisma;
}


Notes:

This is a new Neon database

The issue only happens in production

It started happening ~2 days ago without code changes (just migrate from supabase to neon)

Vercel region default

Prisma clientVersion: 7.0.0

Has anyone seen this error before or knows what could cause Neon to close the socket (UND_ERR_SOCKET) when using poolQueryViaFetch on Vercel?

Any help would be really appreciated 🙏
@NeonDevRel
Was this page helpful?