Prisma with `@cloudflare/vite-plugin`
Did somebody manage to run
prisma
with @cloudflare/vite-plugin
? I am trying use react-router
with Cloudflare and no luck. I tried both prisma-client
and prisma-client-js
providers and it doesn't work.8 Replies
You opted for speed from this bot. Let's conjure up an answer right now!
Running Prisma with @cloudflare/vite-plugin (or similar Vite-based Cloudflare integrations) can be tricky due to how Vite bundles dependencies and how Prisma expects to be used in edge environments like Cloudflare Workers or Pages.
Key points from the knowledge sources:
- When using Vite (or plugins like @cloudflare/vite-plugin), you often need to externalize Prisma dependencies in your Vite config. If you don't, Vite may try to bundle Prisma, which can break things, especially in SSR or edge environments. For example, in a Hono + Cloudflare Pages setup, adding the following to your Vite config can resolve issues:
Or, if using a plugin like
Yes, it is possible to run Prisma with Vite and Cloudflare, but you must: - Externalize Prisma in your Vite config. - Use the correct dr iver adapter and enable
@hono/vite-cloudflare-pages
, you can pass the external
option directly to the plugin Error thrown using PrismaClient in Cloudflare Pages project.
- For React Router, there was a related issue where Vite misconfiguration caused Prisma resolution errors. Upgrading React Router to v7.1.2+ and ensuring proper Vite config (externalizing Prisma) resolved the issue for some users @prisma/client failed to resolve entry.
- If you are targeting Cloudflare Workers/Pages, you must use Prisma's Driver Adapters (e.g., @prisma/adapter-d1
for D1) and enable the driverAdapters
preview feature in your schema.prisma
. Standard Prisma Client will not work in these environments Unable to run prisma with cloud cloudfare workers.
- If you see errors like "PrismaClient is not configured to run in Cloudflare Workers," it means you need to use the correct adapter and configuration.
Summary:Yes, it is possible to run Prisma with Vite and Cloudflare, but you must: - Externalize Prisma in your Vite config. - Use the correct dr iver adapter and enable
driverAdapters
in your Prisma schema.
- For React Router, ensure you are using a compatible version and proper Vite config.
If you still encounter issues, please share your Vite config and Prisma setup for more targeted help.
🤔 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.When using
I am hitting
No such module "node:os".
this is most likelly issue on Cloudflare side, node compact mode doesn't work properly :shrug:
When using
There is error @prisma/client/runtime/query_engine_bg.sqlite.wasm" not found. Does the file exist?
Could you try adding the preview feature
queryCompiler
as well?Same
@prisma/client/runtime/query_engine_bg.sqlite.wasm" not found. Does the file exist?
🙈
What I did is basically pnpm create cloudflare prisma-app --framework=react-router
I’ll have to look into this more, but make sure you re-generated your client
I tried all possible combinations 🙈 I was expecting this is going to work fine. It's not the case, so hopefully soon 🤞
https://github.com/cloudflare/workers-sdk/pull/8283 I think this is same issue 😅
GitHub
vite-plugin: Reproduce hanging prisma issue by justinvdm · Pull Re...
Context
We're running into an issue when using prisma with @cloudflare/vite-plugin, where calls to the db (e.g. db.users.findMany()) cause the request into the worker to hang indefinitely (...
I had to do this