Latest Prisma (2.24.x) version breaks some pnpm projects when generating models
See original GitHub issueBug description
I have a pnpm
project and was running fine on Prisma 2 v2.23.x and lower. But when I upgraded to 2.24.1 my project broke and was unable to resolve the models after running npx prisma generate
.
I will share some simple examples of how to reproduce. But simply put if you run npx prisma generate
in a pnpm
project that has subprojects that by default hoist dependencies, the latest version does not seem to correctly place the generated @prisma/client
code in the correct place, thus the project does not know any of the generated models anymore. I’m not sure what broke between versions but it’s only in 2.24.x where this happens.
NOTE: I asked about this in the Prisma Slack channel and was advised to post this as a bug in Github. Someone had thought a change to path resolution in 2.24.x might be the culprit.
How to reproduce
- Switch to Prisma 2.24.x
- type
npx prisma generate
You’ll then see the following response (note the main difference in responses from 2.23.x and earlier to 2.24.x is that 2.24.x replies with .node_modules/xxx
where 2.23.x and earlier response with ../../node_modules/xxx
):
➜ api git:(MyGitBranch) ✗ npx prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
✔ Generated Prisma Client (2.24.1) to ./node_modules/@prisma/client in 185ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
```
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
```
Expected behavior
npx prisma generate
will correctly place the generated file in the root node_modules
directly like so and no broken links the project will exist:
➜ api git:(MyGitBranch) ✗ npx prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
✔ Generated Prisma Client (2.24.1) to ./../../node_modules/.pnpm/@prisma/client@2.24.1_prisma@2.24.1/node_modules/@prisma/client in 640ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
```
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
```
Prisma information
Not sure this matters…
Environment & setup
- OS: any
- Database: PostgreSQL
- Node.js version: v14.15.4
Prisma Version
➜ api git:(mygitbranch) ✗ npx prisma -v
Environment variables loaded from .env
prisma : 2.24.1
@prisma/client : 2.24.1
Current platform : darwin
Query Engine : query-engine 18095475d5ee64536e2f93995e48ad800737a9e4 (at ../../node_modules/.pnpm/@prisma/engines@2.24.1-2.18095475d5ee64536e2f93995e48ad800737a9e4/node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli 18095475d5ee64536e2f93995e48ad800737a9e4 (at ../../node_modules/.pnpm/@prisma/engines@2.24.1-2.18095475d5ee64536e2f93995e48ad800737a9e4/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 18095475d5ee64536e2f93995e48ad800737a9e4 (at ../../node_modules/.pnpm/@prisma/engines@2.24.1-2.18095475d5ee64536e2f93995e48ad800737a9e4/node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 18095475d5ee64536e2f93995e48ad800737a9e4 (at ../../node_modules/.pnpm/@prisma/engines@2.24.1-2.18095475d5ee64536e2f93995e48ad800737a9e4/node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 18095475d5ee64536e2f93995e48ad800737a9e4
Studio : 0.397.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:11 (5 by maintainers)
Top GitHub Comments
After working with @millsp in Slack (thank you Millsp!) I found I additionally was importing PrismaClient from
@primsa/client
(instead of.prisma/client
). After this change my app was working with preliminary tests - which is awesome so thank you all. I am testing in 2.25.0 but I assume this would also test well for 2.24.0.I should note that the only change I had to make was changing my model and PrismaClient imports from
@prisma/client
to.prisma/client
. And talking to @millsp in Slack, this definitely should fix the issue where PNPM fully hoisted mono repos before could only have one project with Prisma (because multiple subprojects would compete/overwrite their model defs withprisma generate
in the rootnode_modules
directory). This fix and solution might fix that. Just my 2c here.Anyway again thank you all for your help and an awesome product!
Hey @mpolitowski-iws, sorry that you are experiencing trouble. Would you mind sharing your setup? From what I know, this is an intended change. Let’s assume that you have multiple packages (or services), and each of them use a different database, generate a different
prisma
client.You are using
pnpm
, which hoists the package to the root of your project. This could lead to problems if you had many clients to generate, they would overwrite themselves into the root (hoisted)node_modules
. If your root is project is empty, you should not be able to rungenerate
. You should also import.prisma/client
instead since the hoisted runtime will not be able to find any generated client around it.Now instead, we recommend that you run your
pnpx prisma generate
into the sub-projects’s folder. It will generate the client into thenode_modules
of your sub-projects. However, I get the feeling that our setups differ so could you please put up a minimal project so that I can take a look? Thanks.