#Is there anyway to use any SQL database on Prisma (Next.JS)?
1 messages · Page 1 of 1 (latest)
Bump
Hi there, please don't bump threads.
To your question, could you provide more information? What issues are you running into? What have you tried already? Where is your application being deployed? What kind of database are you using and where have you deployed it?
The more information you can provide, the better we can help
Server Error
PrismaClientValidationError: PrismaClient failed to initialize because it wasn't configured to run in this environment (Vercel Edge Functions or Edge Middleware).
In order to run Prisma Client in an edge runtime, you will need to configure one of the following options:
- Enable Driver Adapters: https://pris.ly/d/driver-adapters
- Enable Accelerate: https://pris.ly/d/accelerate
We get this error however we do not want to use Prisma Accelerate currently and In the page it was said that pg currently doesn't work. I was wondering if there was anyway to overcome this issue.
Our application is currently deployed locally and we are using PostgreSQL on an Ubuntu Server Focal
Have you enabled the driver adapters preview feature? https://pris.ly/d/driver-adapters
Also, as you said, pg isn't supported in the Vercel edge environment. https://www.prisma.io/docs/orm/prisma-client/deployment/edge/deploy-to-vercel#using-an-edge-compatible-driver
You may want to try @prisma/pg-worker and @prisma/adapter-pg-worker and see if that resolves your issues. https://www.npmjs.com/package/@prisma/adapter-pg-worker https://www.npmjs.com/package/@prisma/pg-worker
Prisma's driver adapter for "@prisma/pg-worker". Latest version: 5.12.1, last published: 4 days ago. Start using @prisma/adapter-pg-worker in your project by running npm i @prisma/adapter-pg-worker. There are no other projects in the npm registry using @prisma/adapter-pg-worker.
Prisma's lightweight version of "pg" for workers. Latest version: 5.12.1, last published: 4 days ago. Start using @prisma/pg-worker in your project by running npm i @prisma/pg-worker. There are no other projects in the npm registry using @prisma/pg-worker.
Hey Jon,
I just tried @prisma/pg-worker and @prisma/adapter-pg-adapter and got
Build Error
Failed to compile
Next.js (14.2.0-canary.62)
cloudflare:sockets
Module build failed: UnhandledSchemeError: Reading from "cloudflare:sockets" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "cloudflare:" URIs.
And here is my Next.JS info
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:34 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8103
Available memory (MB): 8192
Available CPU cores: 8
Binaries:
Node: 20.10.0
npm: 10.2.5
Yarn: 1.22.11
pnpm: 6.14.6
Relevant Packages:
next: 14.2.0-canary.62 // Latest available version is detected (14.2.0-canary.62).
eslint-config-next: 14.1.4
react: 18.2.0
react-dom: 18.2.0
typescript: 5.4.4
Next.js Config:
output: N/A
And how i'm currently initiating Prisma Client
import { Pool } from '@prisma/pg-worker'
import { PrismaPg } from '@prisma/adapter-pg-worker'
import { PrismaClient } from '@prisma/client'
// Learn more about instantiating PrismaClient in Next.js here: https://www.prisma.io/docs/data-platform/accelerate/getting-started
const pool = new Pool({ connectionString: process.env.DATABASE_URL })
const adapter = new PrismaPg(pool)
const prismaClientSingleton = () => new PrismaClient({ adapter })
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined;
};
const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
export default prisma;
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
If you need anymore information, let me know.
Let me confirm with our engineering team about our Vercel limitations around PostgreSQL
If PostgreSQL doesn't work, let me know which SQL database(s) work. Thanks
So the Vercel runtime has limited support for drivers. A few work. Those are noted here: https://www.prisma.io/docs/orm/prisma-client/deployment/edge/deploy-to-vercel#using-an-edge-compatible-driver
If your database is in Neon or Vercel Postgres, you can use the Neon database driver and Neon driver adapter.
If you’re using PlanetScale, you can use the PlanetScale driver and driver adapter.
If you’re using Turso, you can use the libsql client and driver adapter.
Unfortunately, those are the only options. This is due to TCP connections not being available in the Vercel Edge environment, which makes most existing db clients not work.
@quartz barn
Is there currently any workaround to this or any databases that work for the Vercel runtime?
You would have to talk with Vercel. Those are the only options I know of that work with Vercel and Prisma
Okay, thanks.
Another addon question, Is there anyway to make my own data proxy and make Prisma use my data proxy?
Do you mean run your own Prisma Data Proxy? If so, that is not possible.
It is possible to set up and use your own proxy (like PgBouncer) but that still requires a TCP connection (which Vercel's edge runtime does not support).
At the end of the day, this is a limitation of the Vercel runtime.
I found something called Neon WSProxy, I was wondering if I can use that.
I'm sorry, I haven't used that so I don't know. It appears to be associated with https://neon.tech though, so in that case I would instead recommend using our information about Neon or Vercel Postgres.
Here is the GitHub Repo for it: https://github.com/neondatabase/wsproxy
From what it looks like, it's a lightweight websocket proxy that communicates with the database.