remix: [Bug]: PrismaClient execution fails on @remix-run/cloudflare-workers
What version of Remix are you using?
1.0.4
Steps to Reproduce
- Use create-remix to create a project. Select Cloudflare Workers at that time.
- Install and build prisma.
- Write
new PrismaClient()in theloaderor in app/utils/db.server.ts. - Start up miniflare with
yarn start.
Expected Behavior
new PrismaClient() should run without problems.
Actual Behavior
$ yarn start
yarn run v1.22.17
$ miniflare --build-command "npm run dev:worker" --watch
> dev:worker
> esbuild --define:process.env.NODE_ENV='"development"' --bundle --sourcemap --outdir=dist ./worker
dist/worker.js 609.5kb
dist/worker.js.map 903.5kb
[mf:inf] Build succeeded
true
[mf:err] /Users/myusername/git/remix-tutorial-cloudflare/dist/worker.js:13428
throw new Error(`PrismaClient is unable to be run in the browser.
^
Error: PrismaClient is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues
at new PrismaClient (/Users/myusername/git/remix-tutorial-cloudflare/node_modules/.prisma/client/index-browser.js:153:11)
at build/index.js (/Users/myusername/git/remix-tutorial-cloudflare/build/index.js:76:21)
at __require (/Users/myusername/git/remix-tutorial-cloudflare/dist/worker.js:13:46)
at /Users/myusername/git/remix-tutorial-cloudflare/worker/index.js:3:24
at /Users/myusername/git/remix-tutorial-cloudflare/dist/worker.js:14682:3
at Script.runInContext (node:vm:139:12)
at VMScriptRunner.runAsScript (file:///Users/myusername/git/remix-tutorial-cloudflare/node_modules/@miniflare/runner-vm/src/index.ts:21:12)
at VMScriptRunner.run (file:///Users/myusername/git/remix-tutorial-cloudflare/node_modules/@miniflare/runner-vm/src/index.ts:71:12)
at EventTarget.#reload (file:///Users/myusername/git/remix-tutorial-cloudflare/node_modules/@miniflare/core/src/index.ts:437:38)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
- I have confirmed that this problem does not occur in
remix-run/node. - I have read the official Prisma documentation. I tried to change the alias, but the build fails.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 13
- Comments: 19 (6 by maintainers)
Hey everyone. We have released some changes a few minutes ago in prisma@3.15.0. tl;dr;
PRISMA_CLIENT_ENGINE_TYPE, useprisma generate --data-proxyto enable the Data Proxyimport { PrismaClient } from '@prisma/client/edge'for a Workers-compatible Prisma Client.envaren’t bundled into the generated Prisma Client any longer (see docs)evalare now also fixedThanks everyone, and your feedback is welcome.
this is due to the fact that remix compiles the server-side javascript under
<root>/build/and worker.js then references said built files viaimport * as build from "../build"-> the worker.js ends up importing your build.js file and will obviously not do what’s intended. The quick fix is to either rename the file like you did or change the import to../build/index@aiji42 This is great news, thank you for taking the time to confirm the code and have a great day!
https://github.com/aiji42/remix-esbuild-override/tree/main/examples/prisma-cloudflare
I was able to avoid this problem by creating
worker.build.jsand changing the alias.(When I name the script file for esbuild
build.js, it fails to build. The reason is not known.)