P
Prisma•7mo ago
Mkiza

Error: @prisma/client did not initialize yet.

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"; ...
Jump to solution
5 Replies
Nurul
Nurul•7mo ago
Hey @Mkiza 👋 When exactly are you getting this error? Does it happen when you try to run this locally? Or does it occur when your app is deployed? If this happens on your deployed app, then is prisma generate command a part of your build script?
Mkiza
MkizaOP•7mo ago
Hey @Nurul (Prisma) this happens when I run my app locally. The command executes fine, but when I access dashboard pages I get the error
Nurul
Nurul•7mo ago
Okay, is your repository open source? If yes, can you share the repository link? It's difficult to predict what might be going wrong without looking at the code.
Solution
ketzo
ketzo•7mo ago
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;
Then I just import prisma from @/lib/prisma.ts wherever I want to use the client.
Mkiza
MkizaOP•7mo ago
Reed thank you so much I tried this and it worked!:heart: Sorry for not getting back Nurul, I tried Reeds suggestion and that did it for me! :starstruck:
Want results from more Discord servers?
Add your server