Error: PrismaClient is unable to be run in the browser
Hi all. I have encountered the following problems:
When extending the Prisma client, adding the
$extends
directive causes an application error ‘PrismaClient is unable to be run in the browser.’.
A meaningful part of the stack:
@prisma/[email protected]
@tanstack/[email protected]
@trpc/[email protected]
@trpc/[email protected]
@trpc/[email protected]
[email protected]
[email protected]
I'm using [email protected]
with [email protected]
At first, I thought the problem was related to the way tRPC interacts with Prisma and react-query in queries from the client. But, it turns out that just adding another Prisma client with the directive $extends
is enough to cause the error. Even if it's not being used anywhere in the app code.
The application builds successfully, but when I run it in the browser console I see:
Error: PrismaClient is unable to run in this browser environment, or has been bundled for the browser (running in unknown).
I would be very grateful if you could share your insights and ways to solve this problem2 Replies
Does the error go away if you don't extend the PrismaClient with $extends?
I want to know if this happens only when you are using
withPgTrgm
extension.Yes, If I remove $extends, the PrismaClient works fine
@Nurul (Prisma) The problem also occurs when I add other extensions to PrismaClient, such as Accelerate.
The issue has been pinpointed as a combination involving the tRPC auth function from Clerk (middleware running on Edge) and PrismaClient.