Drizzle TeamDT
Drizzle Team2y ago
3 replies
Jim

Defining websocket for NeonDB connection

Hey all, I'm having issues with using neondb on a playwright/test package in my monorepo. The connections work fine in my nextjs app but fail when running tests.

Error: All attempts to open a WebSocket to connect to the database failed. Please refer to https://github.com/neondatabase/serverless/blob/main/CONFIG.md#websocketconstructor-typeof-websocket--undefined. Details: fetch failed


The error recommends defining a websocket constructor to the config of the neon client like so:

import { neonConfig } from '@neondatabase/serverless';
import ws from 'ws';
neonConfig.webSocketConstructor = ws; 


But currently I'm using the Pool as recommended by drizzle like so:

import { drizzle } from 'drizzle-orm/neon-serverless';
import { Pool } from '@neondatabase/serverless';
import * as schema from "./schema";
import dotenv from "dotenv";
dotenv.config({ path: ".env.local" });

const pool = new Pool({ connectionString: process.env.DB_URL });
export const db = drizzle(pool, { schema })


Pool doesn't accept a webSoctetConstructor, so I'm pretty stuck now lol.

Any ideas? Thanks for reading!
Was this page helpful?