Skip to content

feat: Support prisma >6.7 in standard starter #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
May 22, 2025
Merged

feat: Support prisma >6.7 in standard starter #457

merged 43 commits into from
May 22, 2025

Conversation

justinvdm
Copy link
Collaborator

@justinvdm justinvdm commented May 19, 2025

Context

  • Updates the standard starter
    • to use prisma 6.7
    • to use the new prisma-client generator: prisma will now generate code to a gitignored generated/prisma dir
    • to use the new queryCompiler flag to reduce the size of the WASM (by around ~350KB)

🔁 Prisma >6.7 migration guide for existing projects

Prisma introduced a new client generator (prisma-client) that lets us generate a client specific to Cloudflare workers (via workerd runtime) and ESM - this makes for much simpler and less error prone Vite integration.

This guide walks you through upgrading an existing RedwoodSDK Standard Starter project.

1. ✅ Update Dependencies

Update the following packages in your package.json:

- "@prisma/adapter-d1": "~6.5.0",
- "@prisma/client": "~6.5.0",
- "prisma": "~6.5.0",
+ "@prisma/adapter-d1": "~6.8.2",
+ "@prisma/client": "~6.8.2",
+ "prisma": "~6.8.2",

Also upgrade wrangler to at least ^4.16.0.

- "wrangler": "^4.14.1"
+ "wrangler": "^4.16.0"

**2. 🧬 Update **

schema.prisma

Change the generator block to use the new prisma-client:

-generator client {
-  provider        = "prisma-client-js"
-  previewFeatures = ["driverAdapters"]
-  output          = "../node_modules/.prisma/client"
+generator client {
+  provider = "prisma-client"
+  runtime = "workerd"
+  moduleFormat = "esm"
+  generatedFileExtension = "ts"
+  importFileExtension = "ts"
+  output = "../generated/prisma"
+  previewFeatures = ["queryCompiler", "driverAdapters"]
}

3. 🗂️ Adjust TypeScript Paths

In tsconfig.json:

- ".prisma/*": ["./node_modules/.prisma/*"]
+"@/*": ["./src/*"],
+ "@generated/*": ["./generated/*"]

Then update imports from @prisma/client to @/db.


4. 🛠️ Refactor DB Client Usage

Replace your src/db.ts with the latest in the standard starter:

https://github.com/redwoodjs/sdk/blob/main/starters/standard/src/db.ts


5. 📁 Add to .gitignore

+generated/

6. 📦 Re-generate Client

After updating schema.prisma:

pnpm prisma generate

7. 🧪 Test Everything

Check your queries work in development and deployments.


Notes

Steps taken

https://gist.github.com/justinvdm/24a9f316f7c5148be852c4660e5f0481

Update: 22 May 2025

  • We're now in a position to merge this, working as expected in dev and production, see steps taken for more

Update: 21 May 2025

Update: 19 May 2025

  • Goal: ==Upgrade to Prisma >=6.7, remove Prisma-specific Vite logic from RedwoodSDK, avoid WASM if possible, and maintain backwards compatibility.

  • Steps Taken:

    • Upgraded to Prisma 6.8.2 with queryCompiler and driverAdapters.

    • Tried out different vite configurations and aliases to target new Prisma client structure.

    • Tested various entry points (edge.js, index.js, wasm.js) and generation configs

    • Validated new prisma-client generator for workerd + esm output.

  • Current Status: Generated client works and loads in dev with SDK changes. DB client instantiation succeeds. Queries fail due to WASM module resolution error during runtime.

  • Blocking Issue: Cloudflare's Vite plugin fails to resolve Prisma's WASM module path, likely due to pnpm's path format (__) interfering with Cloudflare's module detection regex. Investigating patch to regex logic in @cloudflare/vite-plugin.

  • Findings:

    • Not WASM free (yet?): Prisma is not WASM free yet, but they're gradually moving the components out of rust into ts. There's still a 1.66MB wasm file we must work with. Previously it was 2MB.

    • Cloudflare's plugin appears to mangle WASM imports when the file path includes double underscores (__), likely due to greedy regex

    • Switching to Prisma's new ESM generator is promising for us to avoid complexities - e.g. we can avoid having to get optimizeDeps to esm-ify the requires in the generated prisma client (though we'll still need some logic for <6.7)

  • Next Step: Investigate patch, then corresponding PR for Cloudflare's Vite plugin to fix its WASM module resolution regex handling for __ in paths.

Copy link

cloudflare-workers-and-pages bot commented May 19, 2025

Deploying redwood-sdk-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3c685aa
Status: ✅  Deploy successful!
Preview URL: https://dfc273eb.redwood-sdk-docs.pages.dev
Branch Preview URL: https://prisma-6-8-2.redwood-sdk-docs.pages.dev

View logs

@justinvdm justinvdm changed the title feat: Support prisma >=6.7 feat: Support prisma >=6.7 in standard starter May 21, 2025
@justinvdm justinvdm changed the title feat: Support prisma >=6.7 in standard starter feat: Support prisma >6.7 in standard starter May 21, 2025
@justinvdm justinvdm marked this pull request as ready for review May 21, 2025 23:50
justinvdm added a commit that referenced this pull request May 22, 2025
## Context
Takes several changes from #457 for us to use to fix general WASM support.
* We had configuration for supporting Prisma WASM, most of which predated our move to `@cloudflare/vite-plugin`, or were around in the early stages while the CF team were still working on WASM support in the plugin. `@cloudflare/vite-plugin` is now able to support WASM without these hacks and workarounds
* Those workarounds we had also accidentally prevented us from using any other packages that had WASM in them
* With these changes, we now should be able to support **both Prisma <6.7 and >6.7**, as well as unblock supporting other packages that have WASM
* **note:** While Prisma >6.7 is supported, if you're is using the new `prisma-client` generator and `pnpm`, there is an edge case with a fix (cloudflare/workers-sdk#9322) that first needs to be released 
* We'll also be updating the standard starter to use >6.7 Prisma once this same fix has been released and we have upgraded `@cloudflare/vite-plugin`

## Other changes
* Also upgrades
  * @cloudflare/vite-plugin:1.1.0 -> 0.0.0.0-1bae8618b (so we can use cloudflare/workers-sdk#9322 already)
  * wrangler:4.14.1 -> 4.16.0
@justinvdm justinvdm merged commit c042ac9 into main May 22, 2025
5 checks passed
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.

1 participant