"PrismaClient is unable to be run in the browser" in Next.js API route

Title. I have an API route that returns an ImageResponse, and it's showing this error when I try to open it in the browser, doesn't make sense:
5 Replies
Sybatron
Sybatron•2y ago
https://github.com/prisma/prisma/issues/6219 not sure if your issue is the same as this
GitHub
PrismaClient is unable to be run in the browser. · Issue #6219 · p...
Bug description I'm getting an Error: PrismaClient is unable to be run in the browser. How to reproduce Create new Node Project with npm init -y install dependencies npm i next react react-dom ...
whatplan
whatplan•2y ago
can you send the api route code?
isaac_way
isaac_way•2y ago
i did this and it fixed it
export const prisma = (() => {
if (typeof window !== "undefined") {
return {} as unknown as PrismaClient;
}
return (
globalForPrisma.prisma ??
new PrismaClient({
log:
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
})
);
})();
export const prisma = (() => {
if (typeof window !== "undefined") {
return {} as unknown as PrismaClient;
}
return (
globalForPrisma.prisma ??
new PrismaClient({
log:
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
})
);
})();
🤷 i am not connecting to a DB in my browser at all lol that's why this error is weird agreed
Finn
Finn•2y ago
Your probably importing some server code into your client side code somehow, worth a check so you don't leak anything
whatplan
whatplan•2y ago
^^ I agree
Want results from more Discord servers?
Add your server