question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Latest Prisma (2.24.x) version breaks some pnpm projects when generating models

See original GitHub issue

Bug 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

  1. Switch to Prisma 2.24.x
  2. 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mpolitowski-iwscommented, Jun 17, 2021

@mpolitowski-iws I propose you this workaround, please let me know if it works:

import { PrismaClient } from '.prisma/client'

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 with prisma generate in the root node_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!

2reactions
millspcommented, Jun 15, 2021

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 run generate. 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 the node_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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

prisma - npm
Prisma is an open-source database toolkit. It includes a JavaScript/TypeScript ORM for Node.js, migrations and a modern GUI to view and edit ...
Read more >
Prisma 2.26.0 Release - GitClear
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, ... (2.24.x) version breaks some pnpm projects when generating models ...
Read more >
Josh Spooky on Twitter: "This is still broken even for newer ...
Latest pnpm version breaks hoisting of Prisma client files. Experimental Corepack flag pins pnpm version on.
Read more >
winston-prisma-transporter - NPM Package Overview - Socket
Transport Winston logger with Prisma. Version: 0.3.0 was published by walee. Start using Socket to analyze winston-prisma-transporter and ...
Read more >
NOTICE.pdf - NetApp Cloud Central
components that are distributed with the Cloud Portal version Current product. ... @apollo-model/graphql 14.5 ... create-react-project 0.0.13. ISC License ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found