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

pnpm: Can not prisma generate when @prisma/client is not installed in project #9848

Closed
yovanoc opened this issue Oct 19, 2021 · 22 comments · Fixed by #18646
Closed

pnpm: Can not prisma generate when @prisma/client is not installed in project #9848

yovanoc opened this issue Oct 19, 2021 · 22 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
Milestone

Comments

@yovanoc
Copy link

yovanoc commented Oct 19, 2021

Bug description

image

How to reproduce

Just add Prisma to pnpm workspace

Expected behavior

No response

Prisma information

package.json

{
  "name": "adonis",
  "type": "module",
  "license": "MIT",
  "engines": {
    "node": ">=16.0.0"
  },
  "scripts": {
    "clean": "pnpm dlx rimraf \"**/{node_modules,dist,lib,lib-types}\"",
    "build": "bob-esbuild tsc && pnpm prepack -r",
    "test": "pnpm build && pnpm --prefix packages/ai start",
    "lint": "eslint \"./**/*.{ts,tsx}\"",
    "run": "node --experimental-specifier-resolution=node --loader ts-node/esm",
    "prisma": "cross-env NODE_ENV=${NODE_ENV:-development} dotenv-flow -- prisma",
    "migrate:dev": "pnpm prisma migrate dev",
    "migrate:dev:create": "pnpm prisma migrate dev --create-only",
    "migrate:deploy": "pnpm prisma migrate deploy",
    "migrate:reset": "pnpm prisma migrate reset",
    "migrate:resolve": "pnpm prisma migrate resolve",
    "prisma:generate": "pnpm prisma generate",
    "prisma:generate:watch": "pnpm prisma generate --watch",
    "prisma:seed": "pnpm prisma db seed",
    "prisma:studio": "pnpm prisma studio"
  },
  "devDependencies": {
    "@types/node": "^16.11.1",
    "@typescript-eslint/eslint-plugin": "^5.1.0",
    "@typescript-eslint/parser": "^5.1.0",
    "cross-env": "^7.0.3",
    "dotenv-flow-cli": "^1.0.0",
    "esbuild": "^0.13.8",
    "eslint": "^8.0.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "prettier": "^2.4.1",
    "prisma": "^3.2.1",
    "ts-node": "^10.3.0",
    "typescript": "^4.5.0-dev.20211018"
  },
  "dependencies": {
    "bob-esbuild": "^2.0.1",
    "bob-esbuild-cli": "^2.0.0"
  }
}

Environment & setup

  • OS: MacOS
  • Database: PostgreSQL
  • Node.js version: 16.11.1

Prisma Version

prisma                  : 3.3.0
@prisma/client          : 3.3.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 33838b0f78f1fe9052cf9a00e9761c9dc097a63c (at node_modules/.pnpm/@prisma+engines@3.3.0-30.33838b0f78f1fe9052cf9a00e9761c9dc097a63c/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 33838b0f78f1fe9052cf9a00e9761c9dc097a63c (at node_modules/.pnpm/@prisma+engines@3.3.0-30.33838b0f78f1fe9052cf9a00e9761c9dc097a63c/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 33838b0f78f1fe9052cf9a00e9761c9dc097a63c (at node_modules/.pnpm/@prisma+engines@3.3.0-30.33838b0f78f1fe9052cf9a00e9761c9dc097a63c/node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 33838b0f78f1fe9052cf9a00e9761c9dc097a63c (at node_modules/.pnpm/@prisma+engines@3.3.0-30.33838b0f78f1fe9052cf9a00e9761c9dc097a63c/node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 33838b0f78f1fe9052cf9a00e9761c9dc097a63c
Studio                  : 0.437.0
@yovanoc yovanoc added the kind/bug A reported bug. label Oct 19, 2021
@aladinflux
Copy link

aladinflux commented Oct 20, 2021

I'm having the same issues with prisma@3.2.1. Using pnpm in a workspace, I get that npm issue. I'm suspecting it's the node version (16) with npm@8.0.0 which might be incompatible.

npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
npm ERR! Tracker "idealTree:inflate:" already exists

npm ERR! A complete log of this run can be found in:
npm ERR!     /path/to/.npm/_logs/2021-10-20T04_24_23_448Z-debug.log
Error: Command failed with exit code 1: npm install -D prisma@3.2.1

@yovanoc
Copy link
Author

yovanoc commented Oct 20, 2021

With node v15.14

image

with node v17

image

@aladinflux
Copy link

I switched to node@14 using nvm and it seems to work fine.

@yovanoc
Copy link
Author

yovanoc commented Oct 20, 2021

You're right but too bad to rollback to node14...
moreover it adds package-lock.json ...

@yovanoc
Copy link
Author

yovanoc commented Oct 20, 2021

Oh yes I just figured it out. You have to add @prisma/client too in dependencies at the root of your workspace if this is the place where you run prisma otherwise it tries to install it and fail

@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. topic: auto-package-installation labels Nov 3, 2021
@janpio
Copy link
Member

janpio commented Nov 3, 2021

The missing @prisma/client triggers automatic installation of said package when running prisma generate (as that package is required) using npm install. Seems with the specific versions you are testing this is failing.

Can you please repeat the exact Npm and Node versions you are having these problems? Hopefully we can reproduce with that information and investigate a fix.

@MarcusCemes
Copy link

I'm trying to create a docker image with pnpm and prisma, and I'm running into the implicit creation of a package-json.lock file, which leads me to belive that npm is being run.

I have a Docker based reproduction:

FROM node:17-alpine
WORKDIR /app

COPY prisma prisma
RUN npm i -g pnpm
RUN pnpm add prisma @prisma/client
RUN pnpm i -P
RUN rm -rf node_modules
RUN pnpm i -P

The trick is that there must be a pnpm-lock.yaml file present, if there isn't it works fine (no package-lock.json). The Dockerfile above will create one, delete node_modules and then install dependencies again (you must have a prisma folder in your local project).

$ docker build --tag repro .
$ docker run -it repro sh
/app $ ls
node_modules       package-lock.json  package.json       pnpm-lock.yaml     prisma

I'm trying to create a small image for production, running npm alongside pnpm doesn't help with that. I wouldn't be against the idea of converting the pnpm lock file to an npm one for the final image, but I can't find a safe way to do that.

This is a terminal example of what happens in my own build process:

/app $ ls
package.json    pnpm-lock.yaml  prisma  dist
/app $ pnpm install --prod
...
node_modules/.pnpm/@prisma+client@3.3.0_prisma@3.3.0/node_modules/@prisma/client: Running postinstall script, done in 1m 4.6s
# This step takes a while, but with no output
...
/app $ ls
node_modules       package-lock.json  package.json       pnpm-lock.yaml     prisma

@aqrln
Copy link
Member

aqrln commented Nov 4, 2021

I can confirm that Prisma doesn't seem to detect pnpm and tries to install @prisma/client with npm, which, fortunately, breaks (could have been worse if it npm silently rewrote node_modules ignoring pnpm-lock.yaml). Manually installing @prisma/client before running any Prisma commands prevents that.

@aqrln aqrln added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Nov 4, 2021
@MarcusCemes
Copy link

MarcusCemes commented Nov 4, 2021

Running pnpm add @prisma/client before pnpm install --prod --frozen-lockfile does seem to be a valid workaround for the moment, I've managed to shave off a few dozen MB from the docker image. The only problem I can foresee is that it may not be reproducible as it doesn't use the lockfile, but this is acceptable for now. Thanks!

Edit: Actually, installing @prisma/client beforehand does a full pnpm install it seems, but this will have to do for now. It's also possible to remove the devDependencies key from package.json before adding @prisma/client.

Image analysis

     15 MB  RUN /bin/sh -c npm install --global pnpm # build...
     796 B  COPY prisma prisma # buildkit
    183 kB  COPY package.json pnpm-lock.yaml . # buildkit
    617 MB  RUN /bin/sh -c pnpm add @prisma/client
    4.5 MB  RUN /bin/sh -c pnpm install --prod --frozen-lock...
    181 kB  COPY /app/dist dist # buildkit

@aqrln
Copy link
Member

aqrln commented Nov 4, 2021

@MarcusCemes to make things reproducible and have everything in lockfile, you can add the same versions of prisma to devDependencies and @prisma/client to dependencies and use full pnpm install. There really isn't any specific reason to install @prisma/client as a separate step.

@MarcusCemes
Copy link

MarcusCemes commented Nov 4, 2021

@aqrln That was my original intention, and how I believe it should work. But as I stated above, the reason I'm doing that nasty extra step is because it doesn't seem to play nicely with pnpm. @prisma/client runs npm in the postinstall hook, generates an unwanted package-lock.json and increases my image (node_modules folder) by +25% (200MB).

@aqrln
Copy link
Member

aqrln commented Nov 4, 2021

@MarcusCemes that sounds like a different issue, albeit one that I can't reproduce, unlike the original one in this thread. I feel like there might be some confusion about what happens here, though.

@janpio janpio changed the title pnpm generate issue pnpm: Can not prisma generate when @prisma/client is not installed in project Mar 25, 2022
@janpio
Copy link
Member

janpio commented Mar 25, 2022

Another user hit this in this discussion: #12501

The minimal solution here is to only run npm install when we are sure Npm is actually used. Better might be to also offer a code path for pnpm (similar to how we do it for Yarn).

@ErlanBelekov
Copy link

I have a Dockerfile, and it doesn't help me to add prisma before pnpm install

FROM node:16-alpine as setup

WORKDIR /app

# install pnpm
RUN npm install -g pnpm

COPY .npmrc package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.base.json ./

COPY packages/eslint-config/package.json ./packages/eslint-config/
COPY packages/prettier-config/package.json ./packages/prettier-config/
COPY packages/web/package.json ./packages/web/
COPY packages/shared-utils/package.json ./packages/shared-utils/

# copy prisma schema
COPY packages/server/prisma/schema.prisma ./packages/server/prisma/

COPY packages/shared-utils ./packages/shared-utils/

RUN cd packages/shared-utils && pnpm add @prisma/client@3.15.2 prisma@3.15.2

RUN pnpm install --frozen-lockfile --ignore-scripts

# run custom generate script(pnpm prisma generate)
RUN pnpm --filter "@hub/shared-utils" generate

this is package.json of shared-utils

{
  "name": "@hub/shared-utils",
  "version": "1.0.0",
  "main": "dist/src/index.js",
  "types": "dist/src/index.d.ts",
  "private": true,
  "license": "MIT",
  "scripts": {
    "build": "rm -rf dist && tsc --build",
    "test": "jest",
    "precommit": "eslint --ext .ts \"*/**/*\" --fix && prettier --write .",
    "generate": "pnpm prisma generate",
    "postinstall": "pnpm prisma generate"
  },
  "dependencies": {
    "currency.js": "^2.0.4",
    "@prisma/client": "3.15.2",
    "date-fns": "^2.28.0"
  },
  "devDependencies": {
    "@hub/eslint-config": "1.0.0",
    "@hub/prettier-config": "1.0.0",
    "prisma": "3.15.2"
  },
  "prisma": {
    "schema": "../server/prisma/schema.prisma"
  },
  "prettier": "@hub/prettier-config",
}

@millsp millsp self-assigned this Sep 13, 2022
@millsp millsp added the tech/typescript Issue for tech TypeScript. label Sep 13, 2022
@millsp millsp removed their assignment Sep 13, 2022
@tal-rofe
Copy link

Same here..

@millsp millsp added this to the 4.13.0 milestone Apr 14, 2023
@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!

@lake2
Copy link

lake2 commented May 25, 2023

prisma 4.14.1 did not work

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!

@lake2
Copy link

lake2 commented May 25, 2023

it fails when prisma was hosted to pnpm workspace root node_modules

@millsp
Copy link
Member

millsp commented May 25, 2023

Hey @lake2, can you please open a new issue and giving us some level of reproduction, and maybe the errors you're seeing? Thanks.

@janpio
Copy link
Member

janpio commented Jun 6, 2023

Did you create that issue Pierre asked for @lake2?

@DavidVaness
Copy link

DavidVaness commented Jun 29, 2023

I have the same issue as @lake2 @janpio 😞
Did this issue get created?

@janpio
Copy link
Member

janpio commented Jul 4, 2023

It is not linked here, so probably not, unfortunately. Feel free to do so.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.