N
Neon2y ago
dependent-tan

Neon Serverless + Prisma + Vercel Functions

Hello, I want to leverage the Neon Serverless client + Prismaon an app deployed to Vercel Functions . Neon Docs specifies the following Client instantiation:
import { Pool, neonConfig } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@prisma/client'
import dotenv from 'dotenv'
import ws from 'ws'
dotenv.config()
neonConfig.webSocketConstructor = ws
const connectionString = `${process.env.DATABASE_URL}`
const pool = new Pool({ connectionString })
const adapter = new PrismaNeon(pool)
const prisma = new PrismaClient({ adapter })
import { Pool, neonConfig } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@prisma/client'
import dotenv from 'dotenv'
import ws from 'ws'
dotenv.config()
neonConfig.webSocketConstructor = ws
const connectionString = `${process.env.DATABASE_URL}`
const pool = new Pool({ connectionString })
const adapter = new PrismaNeon(pool)
const prisma = new PrismaClient({ adapter })
However, this results in the following runtime error on Vercel:
Uncaught Exception {"errorType":"TypeError","errorMessage":"t.mask is not a function","stack":["TypeError: t.mask is not a function"," at e.exports.mask (/var/task/.next/server/chunks/380.js:1:18610)"," at f.frame (/var/task/.next/server/chunks/380.js:1:37325)"," at f.send (/var/task/.next/server/chunks/380.js:1:39394)"," at L.send (/var/task/.next/server/chunks/380.js:2:9184)"," at Timeout._onTimeout (/var/task/.next/server/chunks/380.js:10:953)"," at listOnTimeout (node:internal/timers:569:17)"," at process.processTimers (node:internal/timers:512:7)"]}
Uncaught Exception {"errorType":"TypeError","errorMessage":"t.mask is not a function","stack":["TypeError: t.mask is not a function"," at e.exports.mask (/var/task/.next/server/chunks/380.js:1:18610)"," at f.frame (/var/task/.next/server/chunks/380.js:1:37325)"," at f.send (/var/task/.next/server/chunks/380.js:1:39394)"," at L.send (/var/task/.next/server/chunks/380.js:2:9184)"," at Timeout._onTimeout (/var/task/.next/server/chunks/380.js:10:953)"," at listOnTimeout (node:internal/timers:569:17)"," at process.processTimers (node:internal/timers:512:7)"]}
After googling around, I found out that this is a WebSocket problem (or rather lack of WS support in Vercel Functions) . I would like to ask what is the proper way to utilise the Neon Serverless client in Vercel environment?
Neon
Connect from Prisma to Neon - Neon Docs
Prisma is an open source, next generation ORM that lets you to manage and interact with your database. This guide covers the following topics Connect to Neon from Prisma Use connection pooling with Pr...
1 Reply
optimistic-gold
optimistic-gold2y ago
Can you try npm i bufferutil --save-dev ? For more context: https://discord.com/channels/1176467419317940276/1176467419938701375/1196916871367229570 I'll make a note to add this to docs To be clear, are you using Vercel Edge or Vercel Serverless?

Did you find this page helpful?