docs icon indicating copy to clipboard operation
docs copied to clipboard

Document how to use Prisma in monorepos

Open nikolasburk opened this issue 3 years ago • 11 comments

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

nikolasburk avatar Feb 11 '21 08:02 nikolasburk

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

johannesschobel avatar Feb 12 '21 06:02 johannesschobel

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

tsongas avatar Jan 27 '22 16:01 tsongas

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

yorch avatar Jul 16 '22 16:07 yorch

Related https://github.com/vercel/turborepo/pull/979#issuecomment-1183444069

Liam-Tait avatar Jul 17 '22 23:07 Liam-Tait

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 avatar Aug 01 '22 00:08 zomars

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

zomars avatar Aug 01 '22 00:08 zomars

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

leerob avatar Aug 01 '22 21:08 leerob

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.

kokokenada avatar Aug 19 '22 15:08 kokokenada

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.

nikolasburk avatar Aug 22 '22 07:08 nikolasburk

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

kokokenada avatar Aug 22 '22 16:08 kokokenada

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.

skworden avatar Oct 06 '22 05:10 skworden