prisma: `pnpm install` not running `prisma generate`
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
- Make sure PNPM is installed. (https://pnpm.io/installation)
- Clone the reproduction repo:
git clone git@github.com:scriptcoded/prisma-issue-6603.git
- Enter the
app
directory:cd prisma-issue-6603/app
- Install dependencies using PNPM:
pnpm i
- Run the application:
pnpx ts-node index.ts
- 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
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 40
- Comments: 21 (6 by maintainers)
Commits related to this issue
- fix: prisma client not being generated on install (prisma/prisma#6603) — committed to duncannah/duncan-blog by duncannah 2 years ago
- fix(prisma): not properly generating see https://github.com/prisma/prisma/issues/6603#issuecomment-1054227614 — committed to waldo-vision/waldo by Huskydog9988 2 years ago
- Squashed commit of the following: commit 0cef80423ae88e84ab6ee00576bbd5215e24d487 Merge: 47775c0 da59126 Author: Husky <39809509+Huskydog9988@users.noreply.github.com> Date: Fri Dec 23 00:24:05 202... — committed to waldo-vision/waldo by Huskydog9988 2 years ago
- fix(db): generate @prisma/client in postinstall Ref: https://github.com/prisma/prisma/issues/6603 — committed to ojeytonwilliams/freeCodeCamp by ojeytonwilliams a year ago
- fix(db): generate @prisma/client in postinstall Ref: https://github.com/prisma/prisma/issues/6603 — committed to ojeytonwilliams/freeCodeCamp by ojeytonwilliams a year ago
- fix(db): generate @prisma/client in postinstall Ref: https://github.com/prisma/prisma/issues/6603 — committed to ojeytonwilliams/freeCodeCamp by ojeytonwilliams a year ago
- fix(db): generate @prisma/client in postinstall Ref: https://github.com/prisma/prisma/issues/6603 — committed to ojeytonwilliams/freeCodeCamp by ojeytonwilliams a year ago
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:@scriptcoded thanks for your bug report!
At the moment, it gets generated in your workspace’s
node_modules
and not in the package’snode_modules
(if you runpnpx 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 ofpnpm
and the way we resolve the generated.prisma/client
. In short, when you install,pnpm
will put@prisma/client
in your workspace’snode_modules
. This has three effects:.prisma/client
via@prisma/client
because they don’t live in the samenode_modules
folder. The one is in the workspace, and the other is in the package.@prisma/client
it then tries to import the neighbor.prisma/client
. For the reason explained above, this is not possible. Even thoughpnpm
claims to hardlink, this does not happen on the folders (not possible).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 dopnpx prisma generate
in your package’s folder. Not closing the issue until that works automatically on install. Your feedback is very welcome 😃Still happening
I can confirm this. For now you can workaround it by adding a manual postinstall script to your package running
prisma generate
like so:I just ran into this issue. It does work with the
import {PrismaClient} from '../node_modules/.prisma/client
just not sure if it’ll pass our code review process.changing the .prisma to
seems to avoid the issues
I love Prisma, but it doesn’t seem to work for me on
pnpm
, and I assume it also doesn’t work on Yarn 2 for more or less the same reason.Was it such a good idea to make the Prisma client to be generated on
node_modules
, assuming it can change depending on which package management you use? Maybe it wasn’t obvious in the beginning that this would be a problem…We have moved on to NPM workspaces since this issue was created and I can confirm that they suffer from the same issue. The following root package.json file works like a charm for anyone interested.
I should note that it also requires our generator to look like this. The output references the root node_modules:
Just ran into this issue today 😞 pnpm + turborepo
Hey everyone.
pnpm
maintains a cache of all installed dependencies so that it does not need to install them twice. With that, it also prevents apostinstall
hook to run twice. This unfortunately breaks a core assumption. For now we suggest that you use this workaround, until we design a proper fix.Here’s another workaround that worked for me. It does not require us to change Prisma client
output
directory and we can simply import from@prisma/client
as usual.same problem, This’s my methods.
And PrismaClient imported use ‘@prisma/client’, like this
Had to create a bit more complicated workaround because of a few issues.
import { PrismaClient } from '.prisma/client'
not an option because I’m re-exporting prisma from a dedicated db package. Since there’s nopackage.json
in.prisma/client
, browser packages using various derived types would pick up and try to bundleindex.js
, notindex-browser.js
.output = "../node_modules/.prisma/client"
sort of worked, but for some reasondist/*.d.ts
files could resolve the paths and types, but notsrc/*.ts
. Possible related to my personal TS and repo config, but who knows. I’ve spent over a week retooling my monorepo and trying different configs by now.Edit: simplified solution - create a client generation script and add it to package postinstall:
You can define your own output location with defining
output
in thegenerator
block of Prisma Client if that helps - then Prisma Client is generated at that path @andrerpena.Thaaar be dragons in
postinstall
. The kind that loop forever…Proceed with caution.