Vite + D1 + Cloudflare Workers + Prisma
I've used Prisma + D1 + Cloudflare workers before and it's been a great experience.
I'm not trying to use the same tack with Vite + Honox (https://github.com/honojs/honox/tree/main) in the mix.
My vite config uses two plugins:
Using prisma modules causes errors:
e.g.
causes this error
Are there any tricks to a vite config that will work with Prisma client libraries, but also allow the cloudflare worker build plugin to work (to rollup into a single output file with no external dependencies)
GitHub
GitHub - honojs/honox: HonoX - Hono based meta framework
HonoX - Hono based meta framework. Contribute to honojs/honox development by creating an account on GitHub.
2 Replies
You chose to compile with the bot. One moment while I piece together your answer…
Based on the knowledge sources provided, I don't have enough specific information to fully answer your question about using Prisma with Vite, D1, Cloudflare Workers, and Honox. However, I can provide some relevant insights and suggestions based on similar issues reported with Prisma and Vite:
1. Vite and Prisma compatibility issues have been reported before. The error you're encountering seems to be related to how Vite handles module resolution for Prisma.
2. One potential solution that has worked for some users is to modify the Vite configuration to properly resolve Prisma modules. Here's an example of a Vite config that might help:
This configuration attempts to resolve the Prisma client modules correctly for Vite Github Issue #12504.
3. For Cloudflare Workers specifically, make sure you're using the edge-compatible version of Prisma Client. You should import from
@prisma/client/edge
instead of @prisma/client
Github Issue #23882.
4. Ensure that you've generated Prisma Client with the --no-engine
flag for edge compatibility:
5. In your schema.prisma
file, make sure you've enabled the driverAdapters
preview feature:
6. For D1 specifically, you might need to adjust your Prisma schema
and client initialization. Here's an example:
And in your code:
However, please note that these suggestions are based on similar issues and may not directly solve your specific problem with Honox and the Cloudflare Workers build plugin. You might need to experiment with different configurations or reach out to the Honox and Cloudflare Workers communities for more specific guidance on making these tools work together with Prisma.
Short answer: The knowledge sources don't provide a direct solution for your specific setup, but adjusting the Vite configuration, using the edge-compatible Prisma Client, and ensuring proper Prisma setup for Cloudflare Workers might help resolve the issues you're facing.
🤔 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.some additional context on my setup/error
When I try to use Prisma client libraries,
I get errors in my dev server:
When I try to deploy, I get errors:
This is my vite.config.ts file:
These are my npm scripts:
I can make the dev server work by setting ssr.external to a list of the prisma libraries, but that doesn't solve the prod deployment