NeonN
Neon12mo ago
8 replies
awake-maroon

WS to connect to the db failed

I set up prisma to use neon the way it was shown in their docs but i kept getting this error

this is my code for the db setup

/// db.ts

import { Pool, neonConfig } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@prisma/client'
import ws from 'ws'

import { env } from "@/env";

neonConfig.webSocketConstructor = ws

const connectionString = env.DATABASE_URL

const pool = new Pool({ connectionString})

const adapter = new PrismaNeon(pool)

const createPrismaClient = () =>
  new PrismaClient({
    log:
      env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
    adapter
  });

const globalForPrisma = globalThis as unknown as {
  prisma: ReturnType<typeof createPrismaClient> | undefined;
};

export const db = globalForPrisma.prisma ?? createPrismaClient();

if (env.NODE_ENV !== "production") globalForPrisma.prisma = db;

This is the error I am gettting:
[auth][error] SessionTokenError: Read more at https://errors.authjs.dev#sessiontokenerror   
[auth][cause]: 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                       at /home/yash/Documents/Projects/live-code/.next/server/edge/chunks/d4b13_@neondatabase_serverless_index_mjs_523aa6._.js:4297:25                        at async PrismaNeon.performIO (/home/yash/Documents/Projects/live-code/.next/server/edge/chunks/node_modules__pnpm_0ce316._.js:5346:28)                 at async PrismaNeon.queryRaw (/home/yash/Documents/Projects/live-code/.next/server/edge/chunks/node_modules__pnpm_0ce316._.js:5304:21)                  at async /home/yash/Documents/Projects/live-code/.next/server/edge/chunks/a1804_@prisma_client_ca73c2._.js:3249:20
Was this page helpful?