prisma: `prisma generate` fails when using pnpm workspaces because it tries to install prisma dependencies with npm or yarn
Bug description
prisma migrate dev
appears to be running npm to install @prisma/cli
but it fails since my project is a pnpm project.
How to reproduce
- Set up your repo to use pnpm workspaces and
workspace:
protocol in package.json (see https://pnpm.js.org/en/workspaces) - Write a schema.
- Run the initial migration:
pnpx prisma migrate dev --name init --preview-feature
I get the following error:
myapp (master *) $ pnpx prisma migrate dev --name init --preview-feature
Prisma schema loaded from prisma/schema.prisma
Datasource "db": SQLite database "dev.db" at "file:./dev.db"
SQLite database dev.db created at file:./dev.db
The following migration(s) have been created and applied from new schema changes:
migrations/
└─ 20210129014823_init/
└─ migration.sql
Running generate... (Use --skip-generate to skip the generators)
npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "workspace:": workspace:^0.4.0
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/jkim/.npm/_logs/2021-01-29T01_48_26_656Z-debug.log
Error: Command failed with exit code 1: npm install -D @prisma/cli@2.15.0
Expected behavior
No error
Environment & setup
- OS: MacOS
- Database: SQLite
- Node.js version: v10.22.0
- Prisma version: 2.15.0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 24 (9 by maintainers)
Actually I just got past the issue by just manual installing @prisma/client in my local project. I ran:
pnpm add @prisma/client
.This is still reproducible, we should add a special case for pnpm
I think what’s happening here is that when your project doesn’t have
prisma
or@prisma/client
dependencies installed. In that case theprisma-client-js
will try to install it using npm or yarn and then fail.Current workaround:
We need to add pnpm support here: https://github.com/prisma/prisma/blob/ea886f84f2f7923eb93533092cd82be7d4af99aa/packages/sdk/src/predefinedGeneratorResolvers.ts
This isn’t monorepo specific, just pnpm. I have just walked through the Quickstart with pnpm in a clean directory and encountered this. I don’t mind (would rather) install dependencies manually but it isn’t mentioned anywhere on that page (though it does indicate ts-node). Installing
@prisma/client
manually was all that was needed. I just needed to mock up a quick sqlite example and it’s annoying to be commenting on an issue midway through the Quickstart instead.@keyworks could you confirm this issue is fixed using these versions of prisma?
I personally tested in a couple projects and everything seems to work correctly now
I can confirm this fixes the problem in my Rush-based monorepo with
pnpm
:Still doesn’t seem to be working for me:
It appears to be still running
npm install
instead ofpnpm install
.This is my setup:
Adding @prisma/client to the root repo’s dependencies did solve the issue. Thanks much!
Just to say I had this problem (pnpm monorepo, errors during
prisma generate
), I’ve switchedpackage.json
to:And I had this script already in there:
And now things work:
And my app just works again. Thanks 👍
@PabloSzx Here’s a minimal repro: https://github.com/keyworks/prisma-issue-5340
It’s slightly different error behaviour than the one I originally reported but the root cause is the same. When I try to run a migration, it runs
npm
instead ofpnpm
which my repo uses.