NPM Workspaces with two or more @prisma/client dependencies
Asked Answered
M

1

8

I have a monorepo setup. It looks something like this:

  • project
    • node_modules
    • packages
      • my-first-project
        • prisma
          • schema.prisma
      • my-second-project
        • prisma
          • schema.prisma

So both projects (my-first-project and my-second-project) have @prisma/client installed and get there dependencies from the upper node_modules folder.

The thing is that whenever i change something in my schema.prisma file (e.g. in my-first-project) and run npx prisma migrate dev --name whatever it generates all the types and stuff and puts it in the upper node_modules folder. this leads to "type not found" errors on the other project (e.g. my-second-project).

Is there a way to tell npm to keep some dependencies in a separate node_modules folder inside each project?

Morality answered 30/7, 2022 at 13:16 Comment(0)
W
6

You could configure a custom output path to specify the location at which PrismaClient should be generated.

Example:

generator client {
  provider = "prisma-client-js"
  output   = "../src/generated/client"
}

And you should be able to import PrismaClient like this:

import { PrismaClient } from './generated/client'

By generating PrismaClient outside of node_modules should solve your issue.

Wavelength answered 2/8, 2022 at 16:19 Comment(2)
It is not clear to me from your example where I tell Prisma to build to an alternative location.Tefillin
@Tefillin if you mean the generator client ... block, that is from the schema.prisma file.Jurel

© 2022 - 2024 — McMap. All rights reserved.