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
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 Docs: Deploy to Cloudflare 2. Prisma Schema:
Your
- Do not use the default
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:
See example and docsPrisma 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:
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.Conversation continued in GH Discussion