worker error when using Building Nitro Server (preset: cloudflare_pages) and Prisma

adlab.pages.dev build log is attached
13:31:53.588 ✨ Success! Uploaded 0 files (38 already uploaded) (0.62 sec)
13:31:53.589
13:31:54.069 ✨ Upload complete!
13:31:55.513 Success: Assets published!
13:31:56.628 Error: Failed to publish your Function. Got error: Uncaught TypeError: Cannot read properties of undefined (reading 'fd')
at worker.mjs:6782:98 in useColors
at worker.mjs:6678:98 in createDebug
at worker.mjs:13054:40 in debugCall
at worker.mjs:13092:16
at worker.mjs:20707:3
13:31:53.588 ✨ Success! Uploaded 0 files (38 already uploaded) (0.62 sec)
13:31:53.589
13:31:54.069 ✨ Upload complete!
13:31:55.513 Success: Assets published!
13:31:56.628 Error: Failed to publish your Function. Got error: Uncaught TypeError: Cannot read properties of undefined (reading 'fd')
at worker.mjs:6782:98 in useColors
at worker.mjs:6678:98 in createDebug
at worker.mjs:13054:40 in debugCall
at worker.mjs:13092:16
at worker.mjs:20707:3
the nitro server builds
13:31:22.277 ℹ Building Nitro Server (preset: cloudflare_pages)
13:31:42.848 ✔ Nitro server built
13:31:42.917 └─ functions/path.js (1.35 MB) (367 kB gzip)
13:31:42.918 Σ Total size: 1.35 MB (367 kB gzip)
13:31:22.277 ℹ Building Nitro Server (preset: cloudflare_pages)
13:31:42.848 ✔ Nitro server built
13:31:42.917 └─ functions/path.js (1.35 MB) (367 kB gzip)
13:31:42.918 Σ Total size: 1.35 MB (367 kB gzip)
14 Replies
Walshy
Walshy2y ago
The Function has some bad code in it Since it's minified it's hard to know what. I'd suggest running locally to find out wrangler pages dev <out dir>
tony
tony2y ago
that function is being generated from Building Nitro Server (preset: cloudflare_pages)
Walshy
Walshy2y ago
I'm aware I'm just telling you the issue
tony
tony2y ago
thank you. let me see if i can get that page the function is:
import { prisma } from '../prisma'

export default defineEventHandler(async(event) => {
const users = await prisma.user.findMany()
return users
})
import { prisma } from '../prisma'

export default defineEventHandler(async(event) => {
const users = await prisma.user.findMany()
return users
})
very basic
Walshy
Walshy2y ago
One of these things is undefined Again, hard to know with minification
tony
tony2y ago
using https://nitro.unjs.io/deploy/providers/cloudflare#cloudflare-pages would I be able to run the wrangler command locally and pass that preset? looking in https://developers.cloudflare.com/workers/wrangler/commands/#pages i do not see a preset option the directory would be .output/server
Walshy
Walshy2y ago
NODE_PRESET=cloudflare-pages nitro build or something and then just wrangler pages dev <output>
tony
tony2y ago
ty So I have added a data proxy and updated the build script
tony
tony2y ago
and now the error is:
tony
tony2y ago
I have the DATABASE_URL in the pages environment variables
Isaac McFadyen
Have you generated the Prisma project as described in the Prisma guide? https://www.prisma.io/docs/data-platform/data-proxy/use-data-proxy#generate-prisma-client-for-the-data-proxy
make sure that Prisma Client is auto-generated with the --data-proxy flag as described below.
tony
tony2y ago
yes,
import { PrismaClient } from '@prisma/client/edge'

export const prisma = new PrismaClient({
errorFormat: 'minimal'
})

export default defineEventHandler(async() => {
return prisma.user.findMany().catch((error) => {
console.log(error)
})
})
import { PrismaClient } from '@prisma/client/edge'

export const prisma = new PrismaClient({
errorFormat: 'minimal'
})

export default defineEventHandler(async() => {
return prisma.user.findMany().catch((error) => {
console.log(error)
})
})
I have also deployed it as a worker, and although it compiles it takes a very long time to get a response https://users-worker.data-well.workers.dev/
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Kodomeister
Kodomeister9mo ago
I had the same experience (am using Nuxt 3). Tried to connect to Supabase DB (Postgres). Now already tried DataProxy but the error is still the same. Hopefully somebody here can help. Just found the fix. I changed the code to: import { PrismaClient } from "@prisma/client/edge"; and now it is working!