Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prisma generate fails when using pnpm workspaces because it tries to install prisma dependencies with npm or yarn #5340

Closed
keyworks opened this issue Jan 29, 2021 · 24 comments · Fixed by #18646
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: auto-package-installation topic: pnpm topic: prisma generate CLI: prisma generate topic: prisma migrate dev CLI: prisma migrate dev
Milestone

Comments

@keyworks
Copy link

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
@keyworks
Copy link
Author

Actually I just got past the issue by just manual installing @prisma/client in my local project. I ran: pnpm add @prisma/client.

@Jolg42 Jolg42 added the topic: prisma generate CLI: prisma generate label Feb 2, 2021
@pantharshit00
Copy link
Contributor

Looks like we always use npm to install the client package if it is missing. Workaround should suffice here for now but we should recheck this assumption in code.

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. topic: cli-migrate labels Feb 3, 2021
@pantharshit00
Copy link
Contributor

This is still reproducible, we should add a special case for pnpm

@tomhoule tomhoule added this to the 2.23.0 milestone May 5, 2021
@Jolg42 Jolg42 modified the milestones: 2.23.0, 2.24.0 May 19, 2021
@Jolg42 Jolg42 modified the milestones: 2.24.0, 2.25.0 Jun 3, 2021
@tomhoule tomhoule modified the milestones: 2.25.0, 2.26.0 Jun 17, 2021
@Jolg42 Jolg42 changed the title prisma migrate dev fails when using pnpm workspaces prisma generate fails when using pnpm workspaces Jun 29, 2021
@Jolg42 Jolg42 added team/client Issue for team Client. process/candidate and removed team/schema Issue for team Schema. labels Jun 29, 2021
@PabloSzx
Copy link

@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",

@Jolg42 Jolg42 modified the milestones: 2.26.0, 2.27.0 Jun 30, 2021
@gaggle
Copy link

gaggle commented Jul 1, 2021

(BTW if the context is of interest I described this fix in my article-series exploring TS monorepo patterns: https://dev.to/jonlauridsen/attempt-3-build-the-source-4oa3)

@v-morlock
Copy link

We are experiencing the same issue using yarn 2, even when using 2.27.0-integration-fix-sdk-pnpm.2

@Jolg42 Jolg42 changed the title prisma generate fails when using pnpm workspaces prisma generate fails when using pnpm workspaces because it tries to install prisma dependencies with npm or yarn Aug 11, 2021
@Jolg42
Copy link
Member

Jolg42 commented Aug 11, 2021

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

@v-morlock
Copy link

Actually we are using the exact same setup as before - on 2.23.0, everything has been working just fine, on 2.29.0, we are getting the npm-error. We use prisma within a workspace of a yarn2-monorepo.

our new dependencies look like this:

    "@prisma/client": "^2.29.0",
    "prisma": "^2.29.0",

@Jolg42
Copy link
Member

Jolg42 commented Aug 12, 2021

@v-morlock It would be good to open a seperate issue for Yarn 2 since it might be a different, but maybe related problem.
This issue is specific to pnpm.

@ankhzet
Copy link

ankhzet commented Jul 29, 2022

@millsp

So the idea is to override this logic if we find existing lock files

Wouldn't work in some cases, f.e. in rushjs monorepo lock files are kept in a separate subdirectory. Probably better way would be to explicitly state used package manager (f.e. "prisma.packageManager" field in package.json) or to handle this special usecase separately (maybe, search for rush.json in parent directories, but this would add more complexity to the logic and more maintenance burden). Otherwise migrate script errors out with npm ERR! code EUNSUPPORTEDPROTOCOL even if pnpx was used to run the command.

For now manually installing @prisma/client beforehand allows to circumvent the problem.

@pilchard
Copy link

pilchard commented Dec 8, 2022

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.

@savager
Copy link

savager commented Mar 24, 2023

Is there a specific version I can install to avoid this currently? I don't want to move away from pnpm monorepo at the moment.

@millsp
Copy link
Member

millsp commented Mar 24, 2023

We are going to prioritize this issue in the coming weeks. For now, the workaround is to manually add @prisma/client as a dependency.

@savager
Copy link

savager commented Mar 24, 2023

Adding @prisma/client to the root repo's dependencies did solve the issue. Thanks much!

@millsp
Copy link
Member

millsp commented Apr 14, 2023

Hey folks, we have just improved our pnpm detection logic to fix this issue, and we will release this in our 4.13.0 release. That said, you can try it now by installing our dev version. npm install prisma@dev. Feedback welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: auto-package-installation topic: pnpm topic: prisma generate CLI: prisma generate topic: prisma migrate dev CLI: prisma migrate dev
Projects
None yet
Development

Successfully merging a pull request may close this issue.