prisma: Fail to build Prisma with nuxt3 for Cloudflare Workers (via Wrangler)

Bug description

process.stderr.fd is not available in cloudflare workers context, which is used in debug-js/debug

Might be related:

How to reproduce

  1. Setup prisma with nuxt3, I used https://sidebase.io/sidebase/welcome/stacks#merino
  2. Run NITRO_PRESET=cloudflare yarn build
  3. Run npx wrangler dev .output/server/index.mjs --site .output/public --local (see https://nitro.unjs.io/deploy/providers/cloudflare)
  4. See error

Starting a local server log:

[mf:err] return "colors" in i.inspectOpts ? Boolean(i.inspectOpts.colors) : l.isatty(process.stderr.fd);

TypeError: Cannot read properties of undefined (reading 'fd')
    at Function.useColors (node_modules/@prisma/client/runtime/index.js:2639:112)
    at default (node_modules/@prisma/client/runtime/index.js:2243:41)
    at src_default (node_modules/@prisma/client/runtime/index.js:19943:43)
    at decompressFromBase64 (node_modules/@prisma/client/runtime/index.js:20021:14)
    at node_modules/@prisma/client/runtime/index.js:33263:38
    at .nuxt/dist/server/_nuxt/error-500.b19bab8c.js:68:72
    ...

Build log on Cloudflare:

Error: Failed to publish your Function. Got error: Uncaught TypeError: Cannot read properties of undefined (reading 'fd')
  at ... in useColors
  at ... in createDebug
  at ... in debugCall

Expected behavior

No response

Prisma information

// unrelevant
export default eventHandler((event) => {
  if (!prisma) {
    prisma = new PrismaClient({ errorFormat: 'minimal' })
  }
  event.context.prisma = prisma
})

Environment & setup

  • Operating System: Darwin, macOS 13.3, Apple M1 Pro
  • Database: PostgreSQL
  • Node Version: v16.13.0
  • Nuxt Version: 3.0.0
  • Nitro Version: 1.0.0
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: modules, build, typescript
  • Runtime Modules: @nuxtjs/tailwindcss@6.6.5, @huntersofbook/naive-ui-nuxt@0.5.1
  • Build Modules: -

Prisma Version

4.9.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

To test the Prisma Client for Data Proxy that should work on Cloudflare Workers:

  • Edit my-sidebase-project\server\middleware\0.prisma.ts to import @prisma/client/edge instead.
  • yarn build && npx wrangler dev .output/server/index.mjs --site .output/public --local
  • The previous error goes away
  • On opening the browser with the project, an error is thrown:
    [nuxt] [request error] [unhandled] [500] @prisma/client/edge did not initialize yet. Please run "prisma generate --data-proxy" and try to import it again.
    

So instead:

  • npx prisma generate --data-proxy
  • yarn build && npx wrangler dev .output/server/index.mjs --site .output/public --local
  • Opening in browser gives this:
    [nuxt] [request error] [unhandled] [500] Datasource "db" references an environment variable "DATABASE_URL" that is not set
    

So instead:

  • Replace env("DATABASE_URL") in schema.prisma with prisma://foo?api_key=123, also change provider = "sqlite" to provider = "postgresql" to actually be able to use DataProxy
  • npx prisma generate --data-proxy && yarn build && npx wrangler dev .output/server/index.mjs --site .output/public --local
  • And then everything works as expected: image
  • On See example it opens /prisma that indeed tries to connect to foo and fails. It seems to me that Prisma Client for Data Proxy is now working correctly.

Am I missing something @razbakov?

(Update: Pushed all my code to GH at https://github.com/janpio/18593)

@janpio what happens if you switch to @prisma/client/edge?

I updated to prisma 4.12.0 and now I am getting this error:

[mf:err] var Ad = (0, go.promisify)(Ha.default.readFile), Sd = (0, go.promisify)(Ja.default.exec), we = U("prisma:get-platform"), Pd = ["1.0.x", "1.1.x", "3.0.x"];

TypeError: Cannot read properties of undefined (reading 'exec')
    at node_modules/@prisma/client/runtime/library.js:18:11211
    at .nuxt/dist/server/_nuxt/error-500.b19bab8c.js:68:72