P
Prisma3mo ago
PDDO

Cloudflare Workers

Hi! I’m having trouble using Prisma with Cloudflare D1 on Cloudflare Workers. I created two minimal examples: • ✅ This one works: https://github.com/catpddo/test-d1-hono • ❌ This one fails to run on Workers: https://github.com/catpddo/test-d1 Both use the same Prisma + D1 setup, but the second one throws an environment-related error when deployed. I’ve also posted the issue here: 👉 https://github.com/prisma/prisma/discussions/27297 Would really appreciate any ideas or tips! 🙏 English is not my first language, so sorry if anything is unclear.
GitHub
GitHub - catpddo/test-d1-hono
Contribute to catpddo/test-d1-hono development by creating an account on GitHub.
GitHub
GitHub - catpddo/test-d1
Contribute to catpddo/test-d1 development by creating an account on GitHub.
GitHub
❓ Issue: Two Prisma + Cloudflare D1 Projects, Same Setup — One ...
Question Hi everyone, I’m currently working with Prisma + Cloudflare D1 + Cloudflare Workers, and I’m confused by an issue I can’t figure out. English isn’t my first language, so I’ve created two m...
2 Replies
Prisma AI Help
Prisma AI Help3mo ago
You chose to compile with the bot. One moment while I piece together your answer… Hi! Based on the knowledge sources, running Prisma with Cloudflare D1 on Cloudflare Workers requires special configuration. The most common cause of the error you’re seeing (“PrismaClient is not configured to run in Cloudflare Workers”) is not using the correct Prisma setup for the Workers environment. Key points to check: 1. Use Driver Adapters:
You must use Prisma’s Driver Adapters for D1, specifically the @prisma/adapter-d1 package, and initialize the Prisma Client with the adapter inside your Worker handler. Example:
import { PrismaClient } from '@prisma/client'
import { PrismaD1 } from '@prisma/adapter-d1'

export default {
async fetch(request, env) {
const adapter = new PrismaD1(env.DB)
const prisma = new PrismaClient({ adapter })
// ... your code
}
}

import { PrismaClient } from '@prisma/client'
import { PrismaD1 } from '@prisma/adapter-d1'

export default {
async fetch(request, env) {
const adapter = new PrismaD1(env.DB)
const prisma = new PrismaClient({ adapter })
// ... your code
}
}

See example and docs
Prisma Docs: Deploy to Cloudflare 2. Prisma Schema:
Your schema.prisma should use the sqlite provider (for D1) and can set the URL to "null" or an env var, as it’s ignored at runtime:
datasource db {
provider = "sqlite"
url = "null"
}

datasource db {
provider = "sqlite"
url = "null"
}

3. Common Pitfalls:
- Do not use the default @prisma/client without the adapter. - Do not initialize Prisma Client globally—initialize it per request inside the handler to avoid context issues in Workers see discussion. - Make sure your build tool (like Vite) is configured to externalize Prisma dependencies if you’re using frameworks like Hono or Cloudflare Pages see example. If you follow these steps and still see errors, double-check that your deployment matches the working example and that you’re not accidentally using Node. js-specific features or global state. If you need more help, please share the specific error message from the failing repo. Good luck! 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Nurul
Nurul3mo ago
Conversation continued in GH Discussion

Did you find this page helpful?