npmprismanpm-workspaces

NPM Workspaces with two or more @prisma/client dependencies


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

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?


Solution

  • 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.