Skip to content

How to fix the error `PrismaClient is unable to be run in the browser` in Next.js

New Course Coming Soon:

Get Really Good at Git

I ran into this error while working on a Next.js website:

PrismaClient is unable to be run in the browser

I had this page and it all worked fine until I commented one line in my code, in particular in my getStaticProps() method.

In that line I called a method from my Prisma instance, which I imported at the top of the page file.

Basically Next.js will see which code we use in getStaticProps() and will use it for the backend. It will not ship it to the frontend.

When I commented out the line in getStaticProps() where I used Prisma, Next.js included Prisma in my frontend code, and I got that error PrismaClient is unable to be run in the browser

The solution was to also comment (or remove) the Prisma import.

Also remember that getStaticProps() is only called on page routes, not in other components, so if this error comes from a component, you have to move the logic up to the page route component.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching May 21, 2024. Join the waiting list!

Here is how can I help you: