I encounter an issue when trying to integrate the generated @prisma/client
with Supabase Edge functions. Running npx prisma generate
places the client in the default location within my node_modules
folder, inaccessible for edge function usage. To resolve this, I modified my prisma.schema
file by including the output
property, ensuring the client is generated in the correct location as shown below:
generator client {
provider = "prisma-client-js"
output = "./../supabase/functions/_shared/prisma-client"
}
datasource db {
provider = "postgresql"
url = "..."
directUrl = "..."
}
model Users {}
I made several attempts to import the client into my edge functions, but encountered errors each time:
// Attempt #1:
import { createRequire } from 'https://deno.land/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e58789bd838783828895d5bcb3bc9bb4bf93">[email protected]</a>/node/module.ts'
const require = createRequire(import.meta.url)
const cjsModule = require('../_shared/prisma-client')
/* Error: worker thread panicked TypeError: Cannot read properties of undefined (reading 'timeOrigin')
at https://deno.land/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="43393535713b3530313b29">[email protected]</a>/node/perf_hooks.ts */
/* Note: I also tried different versions of the std library */
// Attempt #2:
import { PrismaClient } from '../_shared/prisma-client'
/* Error: Unable to load a local module: "file:///C:/Users/.../supabase/functions/_shared/prisma-client".
Please check the file path. */
// Attempt #3:
import { serve } from 'server'
import { PrismaClient } from '../_shared/prisma-client/index.d.ts'
serve((_req: Request) => {
const prisma = new PrismaClient()
})
/* Error: worker thread panicked Uncaught SyntaxError: Missing initializer in const declaration
at file:///home/deno/functions/_shared/prisma-client/index.d.ts:53:11 */
In an effort to address these issues, I attempted to convert the module from CommonJS to ESM using the cjs-to-es6
npm package, but without success.
My query now remains: Why did my attempts fail, and more importantly, how can I make it work?