-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
generate output relative to node_modules/@prisma/client
#17162
Comments
Yes, that would be useful :) |
We have the same issue as well. This comment highlights an instance where a user encounters an error when trying to use a custom output: This comment highlights how you currently have to work around the above issues, which is what this issue is addressing: |
For mono-repo Have a package for your database e.g. "database-a" with the following: package.json
schema.prisma
index.js
Note that the location of the client may be different depending if you put your schema.prisma file inside the root folder of the package or inside /prisma/ Now you can import your database client using the following
|
Today, I also stumbled upon this issue. We are using npm workspaces, and the entire repo has one |
node_modules/@prisma/client
Would love to bring back a discussion on this. We're big advocates for NX which uses a single node_modules folder. We also commonly have to work with multiple different databases in the same project. It would be huge to be able to generate Prisma clients by a specific name as mentioned above. Since the postinstall hook only accounts for schema.prisma placing it into node_modules requires some custom scripts to handle this which can be annoying. |
Problem
In our NX-based repository. We have several libraries that can contain their own schema.prisma.
The best place to then generate the prisma client is
node_modules/@prisma/client/{module_name}
. Because this is fully supported and does not cause the desired problems.If the path is outside node_modules like
./src/generated
then in the case of multiple schemas it will break with a runtime error message
Error: Could not find mapping for model ...
But to achieve the generation to node_modules you need to specify the path relatively
for example
which doesn't seem very practical to me.
Another problem with this approach is that in subsequent builds and deployments via docker. You need to re-generate @prisma/client. We have written a script that copies all schema.prisma from the libraries the application depends on to the dist folder. We then use the script to have all the @prisma/client re-generated.
which works relatively well. But the problem arises in the path where the @prisma/client is generated. It's not to the node_modules of the application, but is created relative to the application. so it may create multiple node_modules in the parent folders.
Suggested solution
Because prisma if it doesn't have output set automatically generates to node_modules/@prisma/client. I think it would be practical to add an alternative option instead of output, for example clientName, which keeps the path to node_modules/@prisma/client but adds the clientName to path
node_modules/@prisma/client/{clientName}
Additional context
The text was updated successfully, but these errors were encountered: