maybe?
This commit is contained in:
@@ -4,7 +4,7 @@ const globalForPrisma = globalThis as unknown as {
|
||||
prisma: PrismaClient | undefined
|
||||
}
|
||||
|
||||
function getPrisma(): PrismaClient {
|
||||
function getPrismaClient(): PrismaClient {
|
||||
if (!globalForPrisma.prisma) {
|
||||
globalForPrisma.prisma = new PrismaClient({
|
||||
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
|
||||
@@ -13,4 +13,15 @@ function getPrisma(): PrismaClient {
|
||||
return globalForPrisma.prisma
|
||||
}
|
||||
|
||||
export const prisma = getPrisma()
|
||||
// Use a Proxy so `new PrismaClient()` is only called when a property
|
||||
// is first accessed (inside a request handler), NOT at module import time.
|
||||
// This prevents PrismaClientConstructorValidationError during Next.js
|
||||
// static analysis / "Collecting page data" phase.
|
||||
export const prisma = new Proxy({} as PrismaClient, {
|
||||
get(_target, prop) {
|
||||
return Reflect.get(getPrismaClient(), prop)
|
||||
},
|
||||
apply(_target, thisArg, args) {
|
||||
return Reflect.apply(getPrismaClient() as unknown as Function, thisArg, args)
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user