ESM with D1 and prisma-client-js
As far as I know the D1 adapter needs prisma-client-js, but I can't get ESM generated JS with that client. I need to switch to
prisma-client, which does generate ESM, but doesn't work with the D1 adapter.
How can I reconcile the 2?6 Replies
You've gone full bot mode! Let me fetch that AI answer for you ASAP.
You're correct: currently, the D1 adapter for Cloudflare requires the use of the legacy prisma-client-js generator, which only outputs CommonJS (CJS) modules. This means you cannot generate native ESM JavaScript with prisma-client-js, and thus cannot use it seamlessly in a fully ESM project. The new prisma-client generator (introduced in Prisma ORM v6.6.0) does support ESM output, but as of now, it does not work with the D1 adapter—D1 support is only available for prisma-client-js, not the new generator yet.
There is no officially supported way to reconcile these two requirements at this time. If you need to use the D1 adapter, you must use prisma-client-js and work within a CJS environment or use workarounds to import CJS in ESM (such as dynamic import or createRequire), but you will not get a fully native ESM client. If you switch to the new prisma-client generator for ESM output, you lose D1 adapter compatibility.
This limitation is acknowledged in the Prisma community, and ESM support for D1 is not yet available. The Prisma team is actively working on improving ESM support and the new generator, but there is no documented solution or timeline for D1 adapter compatibility with the ESM-enabled prisma-client generator yet. For now, you must choose between D1 support (CJS only) or native ESM output (no D1 support) Prisma ORM 6.6.0: ESM Support, D1 Migrations & MCP Server.
If you need both, you may need to wait for future updates from Prisma.
try this for D1 @will smith
ts-expect error comment because the adapter type is wrong but working.Hmm thanks now I'm getting this, but I'm using vite with react router. I'm guessing vite isn't setup properly for the wasm files
react-router-d1-prisma-norust/@prisma/client/runtime/query_compiler_bg.sqlite.wasm" not found. Does the file exist?Are you running
prisma generate ?Also make sure to delete
generated/prisma before every generation, I've learned this may be an issue. The CLI isn’t necessarily cleaning up.
I use pnpm create cloudflare@latest to create projects with plain React, add TanStack Router after. Everything working fine with dev and prod.
It must be the cloudflare vite plugin that knows to place this in assets.
Regarding the query_compiler_bg.sqlite.wasm error:
Does this suggestion help?
https://github.com/prisma/prisma/issues/27083#issuecomment-2979398021
GitHub
Prisma Postgres Adapter with Turborepo does not work · Issue #2708...
Bug description if I have a turborepo monorepo with a packages/db folder containing my prisma schema, and a apps/web application (Next.JS) and I use the updated prisma with previewFeatures = ["...