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

  1. Set up your repo to use pnpm workspaces and workspace: protocol in package.json (see https://pnpm.js.org/en/workspaces)
  2. Write a schema.
  3. 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)

Most upvoted comments

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 the prisma-client-js will try to install it using npm or yarn and then fail.

Current workaround:

  • Use any version of Prisma (latest recommended)
  • pnpm add @prisma/client
  • pnpm add -D prisma

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

"prisma": "2.27.0-integration-fix-sdk-pnpm.1",
"@prisma/client": "2.27.0-integration-fix-sdk-pnpm.1",

I can confirm this fixes the problem in my Rush-based monorepo with pnpm:

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (2.27.0-integration-fix-sdk-pnpm.1) to ./../../common/temp/node_modules/.pnpm/@prisma+client@2.27.0-integration-fix-sdk-pnpm.1_e65d142a06ef7e93699c380be6b525d3/node_modules/@prisma/client in 784ms
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()
``

Still doesn’t seem to be working for me:

$ pnpx prisma migrate dev --name init
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MySQL database "dev" at "127.0.0.1:3306"

Already in sync, no schema change or pending migration was found.

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!     /home/itp-docker/.npm/_logs/2021-06-30T17_09_15_639Z-debug.log
Error: Command failed with exit code 1: npm install -D prisma@2.27.0-integration-fix-sdk-pnpm.1

It appears to be still running npm install instead of pnpm install.

This is my setup:

$ pnpx prisma --version
Environment variables loaded from .env
prisma               : 2.27.0-integration-fix-sdk-pnpm.1
@prisma/client       : Not found
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 6f7f670adbb07fd4b8862c6d2bcb8c4703065918 (at node_modules/.pnpm/@prisma/engines@2.27.0-2.6f7f670adbb07fd4b8862c6d2bcb8c4703065918/node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 6f7f670adbb07fd4b8862c6d2bcb8c4703065918 (at node_modules/.pnpm/@prisma/engines@2.27.0-2.6f7f670adbb07fd4b8862c6d2bcb8c4703065918/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 6f7f670adbb07fd4b8862c6d2bcb8c4703065918 (at node_modules/.pnpm/@prisma/engines@2.27.0-2.6f7f670adbb07fd4b8862c6d2bcb8c4703065918/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 6f7f670adbb07fd4b8862c6d2bcb8c4703065918 (at node_modules/.pnpm/@prisma/engines@2.27.0-2.6f7f670adbb07fd4b8862c6d2bcb8c4703065918/node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : 6f7f670adbb07fd4b8862c6d2bcb8c4703065918
Studio               : 0.408.0

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 switched package.json to:

    "prisma": "2.27.0-integration-fix-sdk-pnpm.2",
    "@prisma/client": "2.27.0-integration-fix-sdk-pnpm.2"

And I had this script already in there:

    "postinstall": "prisma generate",

And now things work:

$ pnpm install
Scope: all 6 workspace projects
../../node_modules/.pnpm/@prisma+engines@2.27.0-2.6f7f670adbb07fd4b8862c6d2bcb8c4703065918/node_modules/@prisma/engines: Running postinstall script, done in 1.6s
../../node_modules/.pnpm/prisma@2.27.0-integration-fix-sdk-pnpm.2/node_modules/prisma: Running preinstall script, done in 53ms
../../node_modules/.pnpm/prisma@2.27.0-integration-fix-sdk-pnpm.2/node_modules/prisma: Running install script, done in 53ms
../../node_modules/.pnpm/@prisma+client@2.27.0-integration-fix-sdk-pnpm.2_aa989df761f5be952059643708d47aa6/node_modules/@prisma/client: Running postinstall script, done in 998ms

dependencies:
- @prisma/client 2.26.0
+ @prisma/client 2.27.0-integration-fix-sdk-pnpm.2
- prisma 2.26.0
+ prisma 2.27.0-integration-fix-sdk-pnpm.2

../.. preinstall$ npx -y only-allow pnpm
└─ Done in 4.1s
. postinstall$ prisma generate
│ Environment variables loaded from .env
│ Prisma schema loaded from prisma/schema.prisma
│ ✔ Generated Prisma Client (2.27.0-integration-fix-sdk-pnpm.2) to ./../../node_modules/.pnpm/@prisma+client@2.27.0-integration-fix-sdk-pnpm.2_aa989df761f5be952059643708d47aa6/node_modules/@pri
│ 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()
│ ```
└─ Done in 3.3s

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 of pnpm which my repo uses.