Repository navigation
Replies: 1 comment
|
The error In modern Prisma (v5.12+ through v6) deployed to Cloudflare Workers with OpenNext, you do not need Prisma Accelerate or 1. Install dependenciesnpm install @prisma/adapter-pg pg
npm install -D @types/pg2. Enable driver adapters in schemaIn generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}3. Initialize Prisma with the pg pool adapterIn import { Pool } from 'pg';
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '@prisma/client';
const connectionString = process.env.DATABASE_URL;
const pool = new Pool({ connectionString });
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({ adapter });
export default prisma;4. Supabase Connection String on CloudflareEnsure your DATABASE_URL="postgresql://postgres.xxx:[PASSWORD]@aws-0-us-east-1.pooler.supabase.com:6543/postgres?pgbouncer=true"If OpenNext bundles the API route for the Cloudflare workerd runtime, the TCP connection routes through Cloudflare's outbound socket connection pool seamlessly without Accelerate. If this gets your Next.js API routes querying Supabase cleanly, feel free to mark as answer. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Question
So I have a NextJS application and I'm using a Postgres database from Supabase and running Prisma as ORM. I'm using app router and also two API routes.
Everything is smooth locally.
When I tried to deploy to Cloudflare, that's when the nightmare began.
Cloudflare recomends to use Cloudflare Workers instead of Cloudflare Pages when dealing with API, as posted here in their official website. Cloudflare Workers use Edge runtime.
Ok, then.
When reading the doc, it says that I need to use the OpenNext library/deploy-framework to make it work inside of Cloudflare Workers. OpenNext uses Node runtime.
Ok, then again.
I read the whole page in the Prisma documentation about Cloudflare Workers but still got different errors. It's confusing, lacking a correct direction.
I used the same route code for all testing cases. My second API route does not use a database and it's working fine.
So now am I suppose to make Prisma work? I tried these combinations.
1. Prisma Client using /edge version
Error received:
Tried:
2. Prisma Client Node runtime
Error received:
3. Prisma Client Node runtime + PG Adapter
Error received:
4. Prisma Client Edge runtime + PG Adapter
Error received (it does not build):
How to reproduce (optional)
No response
Expected behavior (optional)
No response
Information about Prisma Schema, Client Queries and Environment (optional)
All reactions