How to use Prisma ORM in a Turborepo monorepo
I'm trying to setup Prisma ORM in a Turborepo monorepo. What's the best practice to do that?
1 Reply
You chose to compile with the bot. One moment while I piece together your answer…
To use Prisma ORM in a Turborepo monorepo, the best practice is to set up Prisma as a standalone package (e.g.,
In your monorepo root: If using Prisma Postgres, also add: 2. Initialize Prisma and set up schema
Edit
In
In
Add
Copy your
Ensure
@repo/db) inside your packages directory. This allows you to centralize your schema, generated client, and types, making them reusable across all your apps. Here’s a concise step-by-step guide:
1. Create the database packageIn your monorepo root: If using Prisma Postgres, also add: 2. Initialize Prisma and set up schema
Edit
prisma/schema.prisma to define your models and set the generator output to ../generated/prisma.
3. Add scripts for migration and generationIn
packages/database/package.json:
4. Export the Prisma client and typesIn
packages/database/src/client.ts:
In packages/database/src/index.ts:
5. Import and use in your appsAdd
@repo/db as a dependency in your app’s package.json, then import and use the shared prisma instance.
6. Environment variablesCopy your
.env (with DATABASE_URL) to each app, or use a tool like dotenvx for shared env m
anagement.
7. Configure Turborepo tasksEnsure
db:generate runs before dev or build in your turbo.json to avoid missing client errors.
This setup ensures type safety, avoids duplication, and works seamlessly with Turborepo’s caching and task orchestration features. For more details, see the official Prisma Turborepo guide and example code in the docs.
✅ Great, thanks for letting us know that this solved your question!