PrismaClient is unable to be run in the browser.
See original GitHub issueBug description
I’m getting an Error: PrismaClient is unable to be run in the browser.

How to reproduce
- Create new Node Project with
npm init -y - install dependencies
npm i next react react-dom - install prisma with
npm i -D primsaand thennpm i @prisma/client - init prisma with
npx primsa init - change schema to :
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author String?
}
- push schema to postgresql with
npx prisma db push --preview-feature - create index.js like:
import {PrismaClient} from "@prisma/client"
export {PrismaClient} from "@prisma/client"
const prisma = new PrismaClient()
export default function Page(){
return <div>Hello World</div>
}
- run server
- getting error
Expected behavior
Displaying Hello World but getting an error
Prisma information
Environment & setup
- OS: Ubuntu 20.4
- Database: PostgreSQL on Heroku
- Node.js version: v10.19.0
- Prisma version:2.19.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (1 by maintainers)
Top Results From Across the Web
How to fix the error `PrismaClient is unable to be run in the ...
In that line I called a method from my Prisma instance, which I imported at the top of the page file. Basically Next.js...
Read more >Best practice for instantiating PrismaClient with Next.js
In development, the command next dev clears Node.js cache on run. This in turn initializes a new PrismaClient instance each time due to...
Read more >Server code in *.server.ts getting bundled in Remix JS Client
I am getting an error that says: PrismaClient is unable to be run in the browser. even though PrismaClient is being run inside...
Read more >@prisma/client - npm
Alternatively you can explore the ready-to-run examples (REST, GraphQL, gRPC, plain JavaScript and TypeScript demos, ...) or watch the demo ...
Read more >How to use Prisma in a Next.js app - Daily.dev
We will now use Prisma client library to query the database. ... Error: PrismaClient is unable to be run in the browser.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was having a similar issue. I think a solution is to only initialize the client once and on the server only.
@fugohan You are trying to use Prisma on frontend which is not possible. Either use it in next js api routes: https://nextjs.org/docs/api-routes/introduction or use it in getServerSideProps or getStaticProps: https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering