nestjs-prisma icon indicating copy to clipboard operation
nestjs-prisma copied to clipboard

Support for custom prisma locations

Open kokokenada opened this issue 3 years ago • 4 comments

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 https://github.com/prisma in the root node_modules. The generated .prisma files are installed as a sibling to https://github.com/prisma, so api1 and api2 can clobber each other. One can specify where to generate the files (https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/generating-prisma-client#using-a-custom-output-path), however, nestjs uses @prisma/client to import, so the new location is ignored.

kokokenada avatar Aug 22 '22 16:08 kokokenada

Not using a mono repo but ran into a use case for this due to the checksum check issue if you are on a network cant reach it. that prisma has and figured this could be a good solution to that

ryan-s-singh avatar Aug 25 '22 14:08 ryan-s-singh

I have the same problem

fuergaosi233 avatar Aug 27 '22 11:08 fuergaosi233

I solved this problem by using the path capability of tsconfig

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

// tsconfig.json
...
    "paths": {
      "@prisma/client": [
        "./src/generated/prisma-client"
      ]
    },
...

fuergaosi233 avatar Aug 27 '22 11:08 fuergaosi233

Hi @kokokenada this would be a great feature to support custom prisma locations.

PrismaService is extended by PrismaClient, hence an import statement is required and @prisma/client is used. I am not aware that the import for extends can be dynamically changed.

Thanks @fuergaosi233 for a solution!

I will think about how to solve this feature request.

marcjulian avatar Sep 09 '22 10:09 marcjulian

Hi @kokokenada this would be a great feature to support custom prisma locations.

PrismaService is extended by PrismaClient, hence an import statement is required and @prisma/client is used. I am not aware that the import for extends can be dynamically changed.

Thanks @fuergaosi233 for a solution!

I will think about how to solve this feature request.

not working now. I set the paths too, it still loading from @prisma/client true path, and throw out the error Prisma : 4.6.1

hotrungnhan avatar Nov 16 '22 14:11 hotrungnhan

Please checkout my solution for custom prisma locations https://github.com/notiz-dev/nestjs-prisma/pull/40. This also allows to import multiple PrismaClients if needed.

I am happy to hear your feedback if this covers your use cases and works fine in your projects.

marcjulian avatar Nov 22 '22 10:11 marcjulian