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 lin…


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com

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.


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com


Print Share Comment Cite Upload Translate Updates
APA

flaviocopes.com | Sciencx (2021-05-14T05:00:00+00:00) How to fix the error `PrismaClient is unable to be run in the browser` in Next.js. Retrieved from https://www.scien.cx/2021/05/14/how-to-fix-the-error-prismaclient-is-unable-to-be-run-in-the-browser-in-next-js/

MLA
" » How to fix the error `PrismaClient is unable to be run in the browser` in Next.js." flaviocopes.com | Sciencx - Friday May 14, 2021, https://www.scien.cx/2021/05/14/how-to-fix-the-error-prismaclient-is-unable-to-be-run-in-the-browser-in-next-js/
HARVARD
flaviocopes.com | Sciencx Friday May 14, 2021 » How to fix the error `PrismaClient is unable to be run in the browser` in Next.js., viewed ,<https://www.scien.cx/2021/05/14/how-to-fix-the-error-prismaclient-is-unable-to-be-run-in-the-browser-in-next-js/>
VANCOUVER
flaviocopes.com | Sciencx - » How to fix the error `PrismaClient is unable to be run in the browser` in Next.js. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/14/how-to-fix-the-error-prismaclient-is-unable-to-be-run-in-the-browser-in-next-js/
CHICAGO
" » How to fix the error `PrismaClient is unable to be run in the browser` in Next.js." flaviocopes.com | Sciencx - Accessed . https://www.scien.cx/2021/05/14/how-to-fix-the-error-prismaclient-is-unable-to-be-run-in-the-browser-in-next-js/
IEEE
" » How to fix the error `PrismaClient is unable to be run in the browser` in Next.js." flaviocopes.com | Sciencx [Online]. Available: https://www.scien.cx/2021/05/14/how-to-fix-the-error-prismaclient-is-unable-to-be-run-in-the-browser-in-next-js/. [Accessed: ]
rf:citation
» How to fix the error `PrismaClient is unable to be run in the browser` in Next.js | flaviocopes.com | Sciencx | https://www.scien.cx/2021/05/14/how-to-fix-the-error-prismaclient-is-unable-to-be-run-in-the-browser-in-next-js/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.