Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to use Prisma in monorepos #1288

Open
nikolasburk opened this issue Feb 11, 2021 · 13 comments
Open

Document how to use Prisma in monorepos #1288

nikolasburk opened this issue Feb 11, 2021 · 13 comments
Assignees
Labels
docs Documentation creation, updates or corrections serverless-initiative See #orm-discovery-deployment-and-docs size: L one week topic: monorepo

Comments

@nikolasburk
Copy link
Member

nikolasburk commented Feb 11, 2021

e.g. using:

  • Yarn workspaces
  • Lerna
  • ngx

Note that there's a simple example with Yarn workspaces here: https://github.com/nikolasburk/monorepo-prisma

More context on the internal Slack:

screenshot

image

@mhwelander mhwelander added the docs Documentation creation, updates or corrections label Feb 11, 2021
@johannesschobel
Copy link
Contributor

I would like to add nrwl/nx ( https://github.com/nrwl/nx ) to the list of monorepos.

@tsongas
Copy link
Contributor

tsongas commented Jan 27, 2022

Vercel just bought Turborepo I think this is going to become very important very quickly!

@yorch
Copy link

yorch commented Jul 16, 2022

From what I've been testing, doesn't actually work when using ENV variables unless I place the .env file in the prisma directory.

So for instance, I have this monorepo with yarn workspaces

 |- packages/
     |- server/
         |- package.json
 |- prisma/
     |- schema.prisma
     |- package.json
 |- package.json
 |- .env

Seems like it needs to have the .env file in side the prisma directory instead of reading the file from the file on root

@Liam-Tait
Copy link

Related vercel/turborepo#979 (comment)

@zomars
Copy link

zomars commented Aug 1, 2022

Yes please, also declaring .env files on the root of the monorepo break prisma env() function if prisma schema is not located at prisma/schema.prisma

@zomars
Copy link

zomars commented Aug 1, 2022

From what I've been testing, doesn't actually work when using ENV variables unless I place the .env file in the prisma directory.

So for instance, I have this monorepo with yarn workspaces

 |- packages/
     |- server/
         |- package.json
 |- prisma/
     |- schema.prisma
     |- package.json
 |- package.json
 |- .env

Seems like it needs to have the .env file in side the prisma directory instead of reading the file from the file on root

Yes! +1 to this 🙌🏽

EDIT: Relevant issue as well prisma/prisma#12535

@leerob
Copy link
Contributor

leerob commented Aug 1, 2022

Related example: https://github.com/vercel/turborepo/tree/main/examples/with-prisma

@kokokenada
Copy link

I have an issue with monorepo using npm workspaces and prisma. The set up is there are two microservices that both use prisma (say packages/api1, packages/api2). If the same version of prisma is used in each, npm will create @prisma in the root node_modules. The generated .prisma files are installed as a sibling to @prisma, so api1 and api2 can clobber each other. One can specify where to generate the files, however, other dependencies (i.e. nestjs) uses @prisma/client to import, so the new location is ignored.

@nikolasburk
Copy link
Member Author

however, other dependencies (i.e. nestjs) uses @prisma/client to import, so the new location is ignored.

@kokokenada Do you think this could be configurable in your NestJS app? If no, it might be worth opening an issue in the nest repo or submit a PR to add this option.

@kokokenada
Copy link

kokokenada commented Aug 22, 2022

Thanks for the reply @nikolasburk, and yes, I also opened a ticket there: nestjs/nest#10150 and moved to notiz-dev/nestjs-prisma#31

@skworden
Copy link

skworden commented Oct 6, 2022

I have the same issue as @kokoenada . I can't have a turborepo monorepo with two different Prisma schemas - Prisma gets confused about which schema to use.

@Jolg42 Jolg42 added the serverless-initiative See #orm-discovery-deployment-and-docs label Dec 5, 2022
@sebpowell
Copy link

sebpowell commented Jul 25, 2023

I came across this thread whilst looking for a solution to this: vercel/turborepo#5610

Wondering if anyone has experienced a similar issue?

Edited: found the fix, see here in case it's of use to anyone: https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-monorepo

@antonio-ivanovski
Copy link

For my case where the monorepo will have multiple packages with different schemas, I opted to generate separate prisma clients into separate directories.

// packages/accounts/prisma.schema

generator client {
  provider = "prisma-client-js"
  output   = "./node_modules/@prisma/accounts-client" // <-- note this
  // output   = "./node_modules/@prisma/dashboard-client" // <-- for other package "dashboard"
}
// pacakges/accounts/src/...
import { PrismaClient } from '@prisma/accounts-client';

// ...

Can anyone tell me if this is OK approach or I will have some unexpected issues along the way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation creation, updates or corrections serverless-initiative See #orm-discovery-deployment-and-docs size: L one week topic: monorepo
Projects
None yet
Development

No branches or pull requests