Prisma Client is not configured to run in the edge runtime

I am not using the edge runtime. I am using the nodejs runtime! No Error:
import { PrismaClient } from "@prisma/client";

const globalForPrisma = globalThis as unknown as { db: PrismaClient };
const db = globalForPrisma.db || new PrismaClient();

export default db;

if (process.env.NODE_ENV !== "production") globalForPrisma.db = db;
import { PrismaClient } from "@prisma/client";

const globalForPrisma = globalThis as unknown as { db: PrismaClient };
const db = globalForPrisma.db || new PrismaClient();

export default db;

if (process.env.NODE_ENV !== "production") globalForPrisma.db = db;
Yes Error:
import { PrismaClient } from "@prisma/client";

const extension = {
model: {
user: {
testing() {
return "testing";
},
},
},
};

const getExtendedPrismaClient = () => {
return new PrismaClient().$extends(extension);
};

type ExtendedPrismaClient = ReturnType<typeof getExtendedPrismaClient>;

const globalForPrisma = globalThis as unknown as { db: ExtendedPrismaClient };
const db = globalForPrisma.db || getExtendedPrismaClient();

export default db;

if (process.env.NODE_ENV !== "production") globalForPrisma.db = db;
import { PrismaClient } from "@prisma/client";

const extension = {
model: {
user: {
testing() {
return "testing";
},
},
},
};

const getExtendedPrismaClient = () => {
return new PrismaClient().$extends(extension);
};

type ExtendedPrismaClient = ReturnType<typeof getExtendedPrismaClient>;

const globalForPrisma = globalThis as unknown as { db: ExtendedPrismaClient };
const db = globalForPrisma.db || getExtendedPrismaClient();

export default db;

if (process.env.NODE_ENV !== "production") globalForPrisma.db = db;
No description
10 Replies
ketzo
ketzo2mo ago
I had this same error (within NextJS) because I was trying to use the Prisma client within middleware, which does use the edge runtime. Maybe check that?
Nikita Revenco
Nikita Revenco2mo ago
omg you're right bruh I spend 5 hours on this LOL I need better time management skills thanks mate I have a question, if I can't access the prisma client, and by extension auth, how am I supposed to know if the user is authenticated or not? This is how I used to do it:
const session = await auth();
const session = await auth();
But since I can't use the auth function I have no idea how to get the user's session without using prisma client Since I am using the prisma resolver
ketzo
ketzo2mo ago
I spent 3-4 hours on it myself and also came to ask a question here, hahaha so honestly, I don’t know how you’re supposed to do it in middleware. but you can do that await auth() call in any server component, and authenticate users that way that’s what I’m doing; all my authentication/authorization is done within my React components I’m still using Prisma with next-auth, I just literally have no middleware.ts file at all right now
Nikita Revenco
Nikita Revenco2mo ago
after some digging I found this page: https://www.prisma.io/docs/orm/overview/databases/postgresql I followed the steps and looks like I don't get the error anymore. Looks like I could use the prisma client no problem in middleware now (as long as I don't directly make queries in the middleware) However, I get a different error now: Looks like one of the packages is using crypto somewhere. I'm not using the crypto module anywhere within my code
No description
Nikita Revenco
Nikita Revenco2mo ago
I also found an issue which is directly related to this: https://github.com/brianc/node-postgres/issues/3206
GitHub
Doesn't work with next.js Edge runtime · Issue #3206 · brianc/node-...
I'm writing an app on next.js which I plan to deploy to CloudFlare Pages + Workers. I know there's CloudFlare support, but when running the local development server of next.js, I get the fo...
Nikita Revenco
Nikita Revenco2mo ago
Looks like for now your solution is likely the best workaround at the moment. Would be nice to actually be able to use middleware.ts once this gets fixed though
ketzo
ketzo2mo ago
Hahaha I swear you’re walking the exact same path as me I bet you are using the “bcrypt” package to do Credentials authentication, right? I also couldn’t get that to work; right now I’m just using Google for signin, was gonna come back to email/password later
Nikita Revenco
Nikita Revenco2mo ago
yes!, I am also using bcryptjs
ketzo
ketzo2mo ago
Bcrypt imports the crypto package from node, which isn’t supported in edge runtime I wasn’t running it in middleware but was still getting that error; I never tracked down exactly where it was getting called in Edge, I just ripped it out completely Let me know if you figure out a good way to hash/store passwords, I still need to do that!
Nikita Revenco
Nikita Revenco2mo ago
if I do, ill let you know
Want results from more Discord servers?
Add your server