prisma: `prisma generate` fails in yarn2 / yarn3 workspaces
Bug description
We are using prisma in a yarn2 monorepo consisting of multiple workspaces. We were on version 2.23.0 before and everything was working fine. After upgrading to 2.29.0, prisma tries to run npm to install @prisma/client
, even though it’s already installed in the current folder. This fails, as npm is unable to recognize the imported workspace.
yarn prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "workspace:": workspace:core-api-plugins/article-import-edeka
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/valentinmorlock/.npm/_logs/2021-08-16T10_13_58_979Z-debug.log
Error: Command failed with exit code 1: npm install -D prisma@2.29.1
How to reproduce
clone this repo: https://github.com/v-morlock/prisma-yarn2-repro
yarn
cd workspace
yarn prisma generate
Expected behavior
Prisma should generate its files
Prisma information
Environment & setup
- OS: macOS
- Database: mySQL
- Node.js version: 16.1.0
Prisma Version
2.29.1, stopped working on 2.26.0
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 18
- Comments: 15 (2 by maintainers)
For what it’s worth, the following changes were sufficient in my case. I’m using Prisma with Yarn 3 (zero-installs / plug ‘n’ play) in a monorepo.
I started from @nishils’s suggestion (which worked) and simplified it as much as I could while still keeping everything functional:
prisma
and@prisma/client
as per the docsnode_modules
:pnpify
to be able to run the command-line scriptIf anyone is interested here’s the patch we use to get prisma to work fully with PnP. It just swaps prisma’s bundled
resolve
for an actual require statement, and disables a sanity check that assumes the location of the prisma client, which doesn’t make sense in a PnP world. To get this to work, you’ll also need to add apackageExtension
toprisma
to get it to installresolve
as a dependency. With all this, we have prisma working fully with PnP in a workspace set up. This patch is for prisma 2.30.3, but I’m guessing that you’d only need to perform similar patching in a newer version.this alone has resolved the identical problem i was experiencing.
thank you!
It would be really nice to have a fix for this - as I’ve mentioned, everything was working fine until 2.26.0, so this is really blocking us from upgrading prisma.
I can reproduce this. Looks like we are unable to resolve
@prisma/client
and we are trying to install it vianpm
(as there is notyarn.lock
file the directory which we use to detect usage of yarn). NPM doesn’t support thatworkspace
protocol and it throws the above error. Even if I stop installation of packages usingPRISMA_GENERATE_SKIP_AUTOINSTALL=1
, it can’t resolve the client.Yarn 2/3 is not really supported (#1439) so I am not sure if this is actionable for us but I will still mark this as a confirmed bug.
how I keep using the
prisma generate
with our project (yarn 3, PnP, workspaces):The overall gist is to “run the generation of PrismaClient in docker and get the generated file into your host fs and then expose them with a yarn workspace”
Generating the client files
Use a dockerfile to mount your schema and run the generation
And run this by mounting wherever you are putting your generated files:
using different names for the one inside the schema and the one when mounting the file system just to showcase what is what
docker build -t prismagen .
docker run -v $(PWD)/output:/app/generated prismagen
note: here I just used normal paths, you’d have to set up all to match your project structure
Exposing the generated files
assuming you have experience on how to use yarn workspaces
For, this is basically creating a new workspace and use it somewhere else
And then use it in your other workspaces, like:
And then import the stuff
import { PrismaClient } from "@your-project/prisma";