Error: PrismaClient is unable to be run in the browser.

I'm trying to create a build file for my next app but I'm getting the error: Error: PrismaClient is unable to be run in the browser. It says the error is in my /addsubtopics route which is this:
import { db } from "../../lib/db";

export const runtime = "edge"

export async function POST(request: Request) {
try {
const body = await request.json();
const { topicId, subtopicName } = body;

// Perform the necessary logic to create the subtopic for the given topicId
// Use the `db` object to interact with the database and create the subtopic

// Code to create the subtopic
const createdSubtopic = await db.subtopic.create({
data: {
name: subtopicName,
topic: {
connect: {
id: topicId,
},
},
},
});

return new Response(JSON.stringify(createdSubtopic));
} catch (error) {
console.error("Error creating subtopic:", error);
return new Response(null, { status: 500 });
}
}
import { db } from "../../lib/db";

export const runtime = "edge"

export async function POST(request: Request) {
try {
const body = await request.json();
const { topicId, subtopicName } = body;

// Perform the necessary logic to create the subtopic for the given topicId
// Use the `db` object to interact with the database and create the subtopic

// Code to create the subtopic
const createdSubtopic = await db.subtopic.create({
data: {
name: subtopicName,
topic: {
connect: {
id: topicId,
},
},
},
});

return new Response(JSON.stringify(createdSubtopic));
} catch (error) {
console.error("Error creating subtopic:", error);
return new Response(null, { status: 500 });
}
}
I also tried checking to see if I was trying to run PrismaClient in a client component but these are the only places where I use prisma client (attached screenshot) Anyone know how I can fix this?
Solution:
prisma can't run on the edge
Jump to solution
8 Replies
Solution
Neto
Neto2y ago
prisma can't run on the edge
wlvz
wlvzOP2y ago
oh, that makes sense is there any work around to this?
Neto
Neto2y ago
people are trying kylesy and drizzle for that reason
wlvz
wlvzOP2y ago
ill have to switch over then, thanks
Neto
Neto2y ago
Shoubhit Dash
Typesafe Database Queries on the Edge
Edge computing is all the rage. Learn how to get typesafe access to data on the edge using Kysely, Prisma and PlanetScale.
Neto
Neto2y ago
check this post
wlvz
wlvzOP2y ago
i think i'll switch over to drizzle, i've been wanting to use it thanks
Want results from more Discord servers?
Add your server