Skip to content

docs(cloudflare): update the Prisma ORM how-to for Prisma 7 - #227

Open
ankur-arch wants to merge 1 commit into
opennextjs:mainfrom
ankur-arch:docs/cloudflare-prisma-7
Open

ankur-arch wants to merge 1 commit into
opennextjs:mainfrom
ankur-arch:docs/cloudflare-prisma-7

Conversation

@ankur-arch

Copy link
Copy Markdown

The Prisma ORM section of the database how-to says that you should not provide an output directory for the generated client. Prisma ORM 7 sets up the prisma-client generator by default, and that generator requires output, so readers who start from prisma init get conflicting instructions. This PR documents the Prisma 7 generator and keeps the existing instructions for prisma-client-js, which are still correct for that generator.

Changes

Only the ## Prisma ORM section of pages/cloudflare/howtos/db.mdx changes.

  • schema.prisma: shows the prisma-client generator with output and runtime = "cloudflare", names the error you get when runtime is missing (CompileError: WebAssembly.Module(): Wasm code generation disallowed by embedder), and notes that the generated client needs a Turbopack build because webpack fails on the .wasm?module import.
  • The previous "no output directory" instructions move under a prisma-client-js generator heading. They hold on Prisma ORM 6 and on 7 with that generator.
  • next.config.ts: serverExternalPackages is now described as needed only before @opennextjs/cloudflare 1.20.15, matching what howtos/workerd.mdx already says.
  • lib/db.ts examples import PrismaClient from the generated directory. The "Instead of that" D1 example now passes the adapter to PrismaClient, and the PostgreSQL paragraph names the adapter that the code uses (PrismaPg).

Testing

I tested with a fresh Next.js 16.4.5 app, @opennextjs/cloudflare 1.20.19, wrangler 4.170.0 and Prisma ORM 7.10.1. Each case was built with opennextjs-cloudflare build and run in workerd with opennextjs-cloudflare preview, then exercised with a route handler that writes and reads.

  • prisma-client with runtime = "cloudflare" works with @prisma/adapter-d1 on local D1 and with @prisma/adapter-pg on a hosted Postgres database, using the code blocks from this page as they are. runtime = "workerd" works too.
  • Without runtime, the build succeeds and every query fails with the error quoted in the page.
  • With next build --webpack, the build fails on query_compiler_fast_bg.wasm?module.
  • prisma-client-js without output works on Prisma ORM 7.10.1 and 6.19.3, with and without serverExternalPackages, and also with a webpack build on 7.10.1. With a custom output it fails at query time on both versions.
  • A PrismaClient with PrismaPg shared across requests hangs on the second request, so the per-request guidance still applies.

bun run prettier:check and bun next build pass.

Limitations

I could not deploy to Cloudflare from my machine, so D1 and Hyperdrive were only tested with wrangler's local emulation. I did not test adapter versions older than 1.20.15 or Next.js 15; the 1.20.15 boundary comes from howtos/workerd.mdx.

Disclosure: I work at Prisma.

Prisma ORM 7 uses the prisma-client generator, which requires an output
directory and runtime = "cloudflare" to run in workerd. Keep the existing
instructions for the prisma-client-js generator and scope the
serverExternalPackages advice to adapter versions before 1.20.15.
}
```

Run `npx prisma generate` before building your app, then import `PrismaClient` from the output directory as shown in the examples below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the examples below import from ../generated/prisma/client, which only resolves when lib/db.ts is at the project root and the schema is in prisma/. Many apps use a src/ layout. For example, examples/prisma-7 in the adapter repo uses output = "../src/generated/prisma". Maybe make this explicit:

Suggested change
Run `npx prisma generate` before building your app, then import `PrismaClient` from the output directory as shown in the examples below.
Run `npx prisma generate` before building your app, then import `PrismaClient` from the `client` entrypoint in the output directory as shown in the examples below. The import path is relative to the file that imports it, so adjust it to your project layout (or use the `@/` path alias).


If you leave out `runtime`, the app still builds but every query fails in the Worker with `CompileError: WebAssembly.Module(): Wasm code generation disallowed by embedder`.

The generated client imports a WebAssembly module. This works with Turbopack, which is the default bundler since Next.js 16. A webpack build (`next build --webpack`) fails on `query_compiler_fast_bg.wasm?module` with a `Module parse failed` error. If you build with webpack, use the `prisma-client-js` generator described below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: on Next.js 15, webpack is still the default bundler, so people using prisma-client there need to opt into Turbopack. Something like:

Suggested change
The generated client imports a WebAssembly module. This works with Turbopack, which is the default bundler since Next.js 16. A webpack build (`next build --webpack`) fails on `query_compiler_fast_bg.wasm?module` with a `Module parse failed` error. If you build with webpack, use the `prisma-client-js` generator described below.
The generated client imports a WebAssembly module. This works with Turbopack, which is the default bundler since Next.js 16 (on Next.js 15, use `next build --turbopack`). A webpack build (`next build --webpack`) fails on `query_compiler_fast_bg.wasm?module` with a `Module parse failed` error. If you build with webpack, use the `prisma-client-js` generator described below.


`prisma-client-js` is the default generator in Prisma ORM 6 and is still available in Prisma ORM 7. When using this generator, you do not want to provide an output directory for the generated client.

```prisma filename="schema.prisma"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the filename here is different from the block above (prisma/schema.prisma).

Suggested change
```prisma filename="schema.prisma"
```prisma filename="prisma/schema.prisma"

Comment on lines 133 to 134
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]

@vicb vicb Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the snippet still enables driverAdapters, but line 140 tells readers to remove it on 6.16+. It might read better if the snippet showed what most readers should use, with the preview feature called out as only needed on older versions


This is because the generated client needs to be patched by OpenNext to work with Cloudflare Workers. If you provide an output directory, OpenNext will not be able to patch the client and it will not work.

With this generator, replace the `../generated/prisma/client` import with `@prisma/client` in the examples below. Prisma ORM 6.16 and later print a deprecation warning for the `driverAdapters` preview feature, which you can then remove.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
With this generator, replace the `../generated/prisma/client` import with `@prisma/client` in the examples below. Prisma ORM 6.16 and later print a deprecation warning for the `driverAdapters` preview feature, which you can then remove.
With this generator, replace the `../generated/prisma/client` import with `@prisma/client` in the examples below. On Prisma ORM versions before 6.16, you also need to add `previewFeatures = ["driverAdapters"]` to the generator.

@vicb vicb left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR 🙏

I have added a few suggestions inline.

Please address them (by using or discarding the feedback, your call) and ping me when the PR is ready for final approval

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants