Skip to content

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

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.


→ Get my Next.js (pages router) Handbook

→ I wrote 17 books to help you become a better developer:

  • C Handbook
  • Command Line Handbook
  • CSS Handbook
  • Express Handbook
  • Git Cheat Sheet
  • Go Handbook
  • HTML Handbook
  • JS Handbook
  • Laravel Handbook
  • Next.js Handbook
  • Node.js Handbook
  • PHP Handbook
  • Python Handbook
  • React Handbook
  • SQL Handbook
  • Svelte Handbook
  • Swift Handbook
...download them all now!

Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025

Bootcamp 2025

Join the waiting list