Hello everybody! I'm working on a small nextjs project and ran into this error, after entering my info and going to my dashboard page: Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again. export const client = globalThis.prisma || new PrismaClient()
I've tried running the command again, deleting node modules and installing everything again to no avail. Can anybody help out?
Solution
I had a similar issue, and I think I solved it by setting up a separate Prisma client file that looks like this
import { PrismaClient } from "@prisma/client";let prisma: PrismaClient;declare global { var prisma: PrismaClient | undefined;}if (process.env.NODE_ENV === "production") { prisma = new PrismaClient();} else { if (!global.prisma) { global.prisma = new PrismaClient(); } prisma = global.prisma;}export default prisma;
import { PrismaClient } from "@prisma/client";let prisma: PrismaClient;declare global { var prisma: PrismaClient | undefined;}if (process.env.NODE_ENV === "production") { prisma = new PrismaClient();} else { if (!global.prisma) { global.prisma = new PrismaClient(); } prisma = global.prisma;}export default prisma;