From cbbaf747bfa7bf971ab7a7d6feb9fbdbd56a0d8f Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 12 Mar 2026 20:30:36 -0500 Subject: [PATCH] maybe? --- src/lib/prisma.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts index d7539d7..ab9360b 100644 --- a/src/lib/prisma.ts +++ b/src/lib/prisma.ts @@ -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) + }, +})