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.

PNPM install not running prisma generate

See original GitHub issue

Bug description

When installing within a PNPM monorepo the generator isn’t being run. I suspect it might have something to do with PNPM symlinking dependencies and therefore messing with the client postinstall script. Just a guess though.

How to reproduce

Reproduction: https://github.com/scriptcoded/prisma-issue-6603

  1. Make sure PNPM is installed. (https://pnpm.io/installation)
  2. Clone the reproduction repo: git clone git@github.com:scriptcoded/prisma-issue-6603.git
  3. Enter the app directory: cd prisma-issue-6603/app
  4. Install dependencies using PNPM: pnpm i
  5. Run the application: pnpx ts-node index.ts
  6. Observe that the Prisma client has not been generated

Expected behavior

The Prisma client should be generated and the application should run without issues.

Prisma information

Project set up accoring to the Start from scratch guide.

Environment & setup

  • OS: Manjaro Linux x86_64
  • Database: PostgreSQL 12
  • Node.js version: v14.15.2
  • Prisma version:
prisma               : 2.21.2
@prisma/client       : 2.21.2
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine e421996c87d5f3c8f7eeadd502d4ad402c89464d (at ../node_modules/.pnpm/@prisma+engines@2.21.0-36.e421996c87d5f3c8f7eeadd502d4ad402c89464d/node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli e421996c87d5f3c8f7eeadd502d4ad402c89464d (at ../node_modules/.pnpm/@prisma+engines@2.21.0-36.e421996c87d5f3c8f7eeadd502d4ad402c89464d/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core e421996c87d5f3c8f7eeadd502d4ad402c89464d (at ../node_modules/.pnpm/@prisma+engines@2.21.0-36.e421996c87d5f3c8f7eeadd502d4ad402c89464d/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt e421996c87d5f3c8f7eeadd502d4ad402c89464d (at ../node_modules/.pnpm/@prisma+engines@2.21.0-36.e421996c87d5f3c8f7eeadd502d4ad402c89464d/node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : e421996c87d5f3c8f7eeadd502d4ad402c89464d
Studio               : 0.371.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:24
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

18reactions
millspcommented, Feb 28, 2022

Hey @jlarmstrongiv this has not been released as it would cause many side-effects and breaking changes. Issues with automatic pnpm generation have not been fixed. However, if you just want to have multiple generated clients in your monorepo, you can have per-package generation folders (in their node_modules folder) instead of the root one. You can simply add this to your schema:

generator client {
  provider = "prisma-client-js"
  output = "../node_modules/.prisma/client" // <-- generate in your package node_modules, not the root
}
import { PrismaClient } from '.prisma/client' // <-- import the dot generated folder, not @prisma/client
17reactions
millspcommented, Aug 27, 2021

@scriptcoded thanks for your bug report!

At the moment, it gets generated in your workspace’s node_modules and not in the package’s node_modules (if you run pnpx prisma generate). This would be fine for only one package but not many.

Now, there’s another problem, you want to import @prisma/client. That’s not possible because of pnpm and the way we resolve the generated .prisma/client. In short, when you install, pnpm will put @prisma/client in your workspace’s node_modules. This has three effects:

  1. We can’t resolve the .prisma/client via @prisma/client because they don’t live in the same node_modules folder. The one is in the workspace, and the other is in the package.
  2. When you import @prisma/client it then tries to import the neighbor .prisma/client. For the reason explained above, this is not possible. Even though pnpm claims to hardlink, this does not happen on the folders (not possible).
  3. For the same reasons, we would not be able to provide the right types for each package (assuming that you have multiple packages using multiple clients, each with a different schema).
  4. That’s how things are resolved by import / require.

For the reasons above, I suggest that on such a pnpm monorepo setup, you would not import @prisma/client, but you would import the generated .prisma/client directly instead. It would be wise that we document this.

If you would like to give it a try, please use prisma@2.24.0-integration-fix-paths.3 and @prisma/client@2.24.0-integration-fix-paths.3. It still won’t generate automatically on install, but at least you can do pnpx prisma generate in your package’s folder. Not closing the issue until that works automatically on install. Your feedback is very welcome 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ethan Glover - PNPM install not running prisma generate
Lesson learned, don't use Prisma with PNPM. It will cause issues when it hits someone elses' machine. https://lnkd.in/d_UYf8us.
Read more >
Install Prisma Client | node-mysql
Install and generate Prisma Client. To get started with Prisma Client, you need to install the @prisma/client package: $npm install @prisma/client.
Read more >
Using Prisma with Turborepo
If you've already got Prisma set up in your database, ... If a new developer runs dev on an application without running db:generate...
Read more >
@prisma/client - npm
Prisma Client JS is an auto-generated query builder that enables type-safe database access and reduces boilerplate. You can use it as an ...
Read more >
Sveltekit + Docker + Prisma (prisma do not seem to work)
RUN pnpm install COPY prisma ./prisma/ COPY .env ./ RUN npx prisma generate COPY . . RUN pnpm run build FROM node:18-alpine WORKDIR...
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 Hashnode Post

No results found