core
core copied to clipboard
Correct config for Prisma with Supabase on Cloudflare
Describe the bug
I'm trying to relocate my Vercel projects to Cloudflare through NuxtHub. I'm using Prisma ORM with Supabase and on Vercel deploy the project works as expected, but in Cloudflare not. I got 500: Cannot read properties of undefined (reading 'exec'). error but in local works!
Steps to reproduce Steps to reproduce the behavior:
- Install
prismaand@prisma/clientdependencies then addprisma generatetobuildcommand:
{
"name": "esteba-app-appointments",
"private": true,
"type": "module",
"scripts": {
"build": "prisma generate && nuxt build",
},
"dependencies": {
"@prisma/client": "^5.18.0",
"@vueuse/core": "^11.0.1",
"nuxt": "^3.13.0",
"vue": "latest",
},
"devDependencies": {
"prisma": "^5.18.0",
"wrangler": "^3.72.2"
},
"packageManager": "[email protected]"
}
- Create
prisma/schema.prismafile:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
- set supabase credentials on environment variables project
and thats it, on Vercel this works
Expected behavior Request sent as expected
I'm doing my research, and this issue happens to another person Cloudflare issue
Duplicate of #38
Would you mind reading https://github.com/nuxt-hub/core/pull/58/files and see if this works?
Duplicate of #38
Would you mind reading https://github.com/nuxt-hub/core/pull/58/files and see if this works?
The example uses sqlite and ignores the DATABASE_URL but i'm using postgresql with supabase... just dont work
I guess you also read https://www.prisma.io/docs/orm/prisma-client/deployment/edge/deploy-to-cloudflare ?
I had a similar problem, you could try this https://github.com/prisma/prisma/issues/23500#issuecomment-2147548083. It seems to be a problem with Nitro and Prisma
@mtzrmzia I'm late, but in case someone else is having trouble using Supabase + ORM + Cloudflare.
I did some research and found that Cloudflare Workers aren't based on Node, but on V8 which has a subset of the features of Node. That means if you use an ORM, it'll use default a TCP connection to your DB, which it shouldn't be supported afaik from Cloudflare Workers.
So, the solution is either you ditch:
- Supabase for another DB with http support (like Neon or D1)
- Prisma to use "supabasejs" and use PostgREST (to avoid TCP)
- Cloudflare Workers to other serverless platforms that support TCP (like Vercel)
In my case I decided to migrate my DB to Neon, because it was the fastest and with fewer conflicts to my workflows
so i made it work by just:
schema.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
and than:
import { PrismaClient } from '@prisma/client';
import { PrismaPg } from '@prisma/adapter-pg'
import { Pool } from 'pg'
export function getPrismaClient(env) {
const pool = new Pool({ connectionString: env.DATABASE_URL })
const adapter = new PrismaPg(pool)
const prisma = new PrismaClient({ adapter })
return prisma;
}
works like a charm
You could try Prisma with Hyperdrive
- https://github.com/prisma/ecosystem-tests/blob/dev/driver-adapters-wasm/pg-cf-hyperdrive/prisma/schema.prisma
- https://github.com/prisma/ecosystem-tests/blob/dev/driver-adapters-wasm/pg-cf-hyperdrive/src/index.js