# Fix 'Already 10 Prisma Clients are actively running'

> Fix the Next.js Already 10 Prisma Clients are actively running error by exporting one shared PrismaClient instance from lib/prisma.js and reusing it.

Author: Flavio Copes | Published: 2021-05-15 | Canonical: https://flaviocopes.com/nextjs-fix-prismaclient-unable-run-browser/

I was using [Prisma](https://flaviocopes.com/prisma/) in my [Next.js](https://flaviocopes.com/nextjs/) app and I was doing it wrong.

I was initializing a new PrismaClient object in every page:

```js
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
```

After some point, during app usage, I received the error `Already 10 Prisma Clients are actively running` and also a `Address already in use`.

To fix this, I exported this Prisma initialization to a separate file, `lib/prisma.js`:

```js
import { PrismaClient } from '@prisma/client'

let prisma

if (process.env.NODE_ENV === 'production') {
  prisma = new PrismaClient()
} else {
  if (!global.prisma) {
    global.prisma = new PrismaClient()
  }
  prisma = global.prisma
}

export default prisma
```

The production check is done because in development, `npm run dev` clears the [Node.js](https://flaviocopes.com/nodejs/) cache at runtime, and this causes a new `PrismaClient` initialization each time due to hot reloading, so we'd not solve the problem.

I took this code from <https://www.prisma.io/docs/support/help-articles/nextjs-prisma-client-dev-practices>

Finally I imported the exported `prisma` object in my pages:

```js
import prisma from 'lib/prisma'
```
