Next + Cloudflare Workers + D1
I'm trying to use Prisma in a Next app on Cloudflare Workers and D1.
I have gone through all the setup steps and tried to use the ...FORCE_WASM...=1
But on actual deploy, I keep getting
fs.readdir
not available. My understanding is that this should work, that prisma supports edge runtimes (examples for prisma+d1 exist), and that something is not being built or setup right such that prisma doesn't try to use functions it knows it shouldn't in an edge runtime26 Replies
You selected to wait for the human sages. They'll share their wisdom soon.
Grab some tea while you wait, or check out
#ask-ai
if you'd like a quick chat with the bot anyway!Hey 👋
Is your repository open source?
Any way I can try to run the example and debug?
yes, I have a minimal repro for another cloudflare edge runtime issue I'm hitting. Let me make sure I can reproduce the prisma specific issue and point you at the specifics after
@Nurul (Prisma) See this directory: https://github.com/verdverm/cf-repro/tree/main/src/app/repro
works when
yarn dev
fails with the above error with yarn worker:dev
GitHub
cf-repro/src/app/repro at main · verdverm/cf-repro
repro repo for my cf frens. Contribute to verdverm/cf-repro development by creating an account on GitHub.
Im having the same problem
Not with D1 but tried the pg-adapter and even signed up for neon and used that adapter
Stacktrace:
fs.readdir seems to be called here:
@Nurul (Prisma)
PRISMA_CLIENT_FORCE_WASM=1
is supposed to fix this, but it does not
@Joshkop walking back from our errors, to the code you found, we may need to set the binaryTargets
field in our prisma files. It looks like they are poking around the filesystem to figure out what platform they are running on, what version of libssl to use... but we may be able to short-cirtuit these checks
https://github.com/prisma/prisma/blob/02090bb22a32c96dc69f9efb21f70c61191b6478/packages/client/src/runtime/core/engines/library/LibraryEngine.ts#L245
https://www.prisma.io/docs/orm/prisma-client/deployment/serverless/deploy-to-netlify#binary-targets-in-schemaprisma
did not seem to helpfound this very detaild compat chart for CF workers (wrangler)
https://workers-nodejs-compat-matrix.pages.dev/
Workers Node Compat Matrix
demo site
Didn't work for me as well it still tries to get the binary target through the failing function
I don't think the node compat should apply here since Prisma should be edge compatible with the adapters
Since they also have docs for clouflare workers on prisma
💯
seems like there is a disconnect somwhere between prisma, wrangler, open-next, and cloudflare
I may just write SQL by hand and use D1 directly, just use prisma for sql creation, maybe even drop Prisma completely
Are you running the wrangler preview in wsl2?
You might try out drizzle
I'm on the latest wrangler on mac
Drizzle ORM - Cloudflare D1
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Ok then I don't see anything which our repos have in commen other then Prisma opennext and wrangler
I don't mind writing the sql by hand honestly, just thought I'd use prisma because it generates migration files for me
and lets me see the full model without having to piece it together over multiple migration files or inspecting the database
It's really not that bad
Yeah I really want the typescript support for the models
But drizzle also has that and migrations
not using an ORM means it is much easier to move to another language like Go
But I'm pretty far along and switching would take a lot of time
or share the SQL between microservices
This page annoys me: https://orm.drizzle.team/docs/migrations
Drizzle ORM - Migrations
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
the silence from Prisma here gives me pause too
I still think there has to be some build config or whatever which is our problem
Or it's something which opennext introduced in a recent version
Can't think we're the only people trying nextjs Prisma and CF workers
And the only info anywhere with this problem is this discord thread
agree on all of that!
What part ?
I think option 4 is just like prisms migrations
mostly the UX of it, don't give me blocks of little text to figure out what option I need, use headings, and don't make me click to expand details
Ahh yeah fair enough
Anyways Ill see if i can migrate over to drizzle without too much hassle and try that out
Dont think we'll get a solution here in the near future
I'm now hoping that Prisma is also causing my OAuth problems because the client get/set helpers are using Prisma to r/w