prisma: Could not resolve @prisma/client despite the installation that we just tried.

Bug description

I’ve come back to work on a product again after a couple of weeks and it broke (again) which I guess just happens as prisma is evolving quickly but this one I couldn’t figure out the fix.

Locally, it generates fine still, but in the Docker image which our backend deploys it throws this after yarn dlx prisma generate

Error: Could not resolve @prisma/client despite the installation that we just tried.
Please try to install it by hand with npm install @prisma/client and rerun prisma generate 🙏.

(Which I tried and doesn’t make any difference)

I also tried installing prisma globally with npm i -g prisma and the same issue occurs. Same with npx prisma generate too.

npx prisma results in this:

root@53e11231ecb9:/api# npx prisma
internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module '/root/.npm/_npx/141/lib/node_modules/prisma/scripts/preinstall-entry.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! prisma@2.23.0 preinstall: `node scripts/preinstall-entry.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the prisma@2.23.0 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-05-23T17_55_36_862Z-debug.log
Install for [ 'prisma@latest' ] failed with code 1

I did manage to get it to work once by running the yarn dlx command twice, but I can’t remember how, it’s been a few hours now!

Are there any specific changes that happened in the last few weeks that I need to make changes for?

One aspect of this project is that it’s a multi-tenant yarn workspaces repo with a few different packages inside, but the root package includes prisma as a dependency and @prisma/client as a dev dependency (which I’m not sure why, I think it solved another similar issue a couple of months back)

How to reproduce

It’s probably project specific, but just running generate triggers it.

Expected behavior

No response

Prisma information

Schema isn’t relevant. It generates fine on development machine (mac)

Environment & setup

  • OS: Building a Docker image (based on golang:latest)
  • Node.js version: 12.18.3

Prisma Version

prisma               : 2.23.0
@prisma/client       : 2.23.0
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../usr/local/nvm/versions/node/v12.18.3/lib/node_modules/prisma/node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../usr/local/nvm/versions/node/v12.18.3/lib/node_modules/prisma/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../usr/local/nvm/versions/node/v12.18.3/lib/node_modules/prisma/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../usr/local/nvm/versions/node/v12.18.3/lib/node_modules/prisma/node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : adf5e8cba3daf12d456d911d72b6e9418681b28b
Studio               : 0.393.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 19
  • Comments: 53 (7 by maintainers)

Commits related to this issue

Most upvoted comments

This happened to me because I only had @prisma/client installed, and I needed to also install prisma

This happens in npm workspaces too. In npm workspace the deps are installed on the parent directory while @prisma/client appears locally for some reason

did you fix it?

I switched to Typeorm

I came across this in my Docker build.

This can happen if you have “@prisma/client” in the devDependencies. Move it to dependencies

I got it to run successfully, but I had to do this (I think)

  • yarn dlx prisma generate: that fails with the error
  • yarn add @prisma/client
  • yarn dlx prisma generate: fails again
  • yarn dlx prisma generate: magically works

I had this problem, because i didn’t install prisma in my project. lmao.

Okay it seems installing @prisma/client fresh each time works, which is fine!

  generate:
    cmds:
      # Generate database bindings and data model types.
      - yarn add @prisma/client
      - yarn dlx prisma generate

I get this error when I run prisma generate inside node_modules in my library which has @prisma/client as a dependency. Is there any example how to use @prisma/client inside npm library?

My problem was solved by moving prisma from devDependenies to depenencies. The fact is that when installing my library from npm, prisma was not installed because it was in devDependenies and prisma generate was launched from a package that is higher in the folder hierarchy than the project root, this caused error:

Error: Could not resolve @prisma/client despite the installation that we just tried

npm install --save-dev prisma (had the same issue, use this)

This happens in npm workspaces too. In npm workspace the deps are installed on the parent directory while @prisma/client appears locally for some reason

yeah the prisma must be also installed, especially when using pnpm (ensure that the versions are the same)

Dont know how i suddenly got this error when it was working fine until now. I just deleted the node_modules and package-lock. Tried everything but didn’t work then, I did this:

npm cache clean --force
cd packages/db
npm uninstall prisma @prisma/client
npm cache clean --force
npm install prisma@5.22.0 @prisma/client@5.22.0
npx prisma generate #it worked
cd ../..
npm i

so, I think first installing prisma and prisma/client then others worked?

update: happened again but this time didn’t worked so I just

npm uninstall @prisma/client prisma
npm install  @prisma/client
npm i -D prisma

worked

I know this issue is closed, but I wanted to add my own issue:

I’m working in a turborepo monorepo with pnpm. I have multiple packages using prisma, and one of them worked fine with @prisma/client v^5.10.2 and prisma@latest. The other that was giving me the same error described above was using @prisma/client v^5.13.0 and a matching prisma@^5.13.0. Moving the latter versions over to match the former made things magically work.

You are a godsend

npm i --save-dev prisma ts-node @types/node

works for me!.

I am upgrading from yarn 1 to yarn 4 and I am struggling on this for hours, none of the ideas here helped.

This happened to me because I only had @prisma/client installed, and I needed to also install prisma

I love you, I really do

Resolved by yarn add prisma for me

I removed the node_modules,and it magically start works.

I know this issue is closed, but I wanted to add my own issue:

I’m working in a turborepo monorepo with pnpm. I have multiple packages using prisma, and one of them worked fine with @prisma/client v^5.10.2 and prisma@latest. The other that was giving me the same error described above was using @prisma/client v^5.13.0 and a matching prisma@^5.13.0. Moving the latter versions over to match the former made things magically work.

Please open a new issue @ahollenbach as this sounds different enough to get its own investigation. Please make sure to fill the full issue tempalte so we have all information. Thanks.

@Southclaws Are you using Yarn v2? If yes, then this is a duplicate of https://github.com/prisma/prisma/issues/1439

You need to use the node_modules linker to make Prisma work there.

Alternately, you can generate the client in a different location than the default: https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/generating-prisma-client#using-a-custom-output-path

I got the same issue yesterday and my coworker got it today. It was as simple as reinstalling @prisma/client, but by now it should be fixed I guess

I can’t even remember this issue so it’s safe to say it’s probably working fine now!

Hey @Southclaws,

Are you still experiencing this issue? If not, we’d like to close it.

Thank you 🙏

I had the same problem. Resolved it by removing "postinstall": "prisma generate" from scripts in package.json

Fixed it by upgrading Webstorm to the latest version

We just update from 4.2.1 into 4.3.1 and get this?

We do have

"workspaces": [
    "../common"
  ],

in the same package.json where prisma generate fails but this shouldn’t affect the generation?

  prisma:generator  prismaCLIDir /parent/node_modules/prisma +860ms
  prisma:generator  prismaClientDir /parent/service/node_modules/@prisma/client +1ms
Error: Error: Could not resolve @prisma/client despite the installation that we just tried.

Also we have the 4.3.1. “prisma” installed on parent module’s package.json hence /parent/node_modules/prisma.

Yes that was the problem, it used to work because we still had “prisma” on package-lock but anyway fixed by moving from parent package.json:

     "prisma": "4.3.1", <--- this was moved from parent dependencies
    "@prisma/client": "4.3.1"

Why sharing “prisma” with multiple modules doesn’t work although it finds it just okay?

I have this issue as well is nobody able to solve this problem. But I’m as well working on a m1 Max Machine and had problems with the python version. Finally got installed but can’t import …]

This can’t be it does it?

Yup, what @rinogo said. It is reproducible and confusing.

I ended up not creating a ticket, but it looks like 2.26.0 resolved my issue.

Not using yarn 2 and encounter this issue when building in docker as well.

I notice it occurs specifically when upgrading from prisma 2.23.0 -> 2.24.x/2.25.0, and only when upgrading prisma and not @prisma/client, which is fine at 2.24+

Dockerfile

<...>
RUN yarn install
RUN yarn run build:js
RUN dotenv -e .env.development -- yarn prisma generate

Output

 > [10/10] RUN dotenv -e .env.development -- yarn prisma generate:
#14 0.645 yarn run v1.22.5
#14 0.705 $ /node_modules/.bin/prisma generate
#14 1.355 Environment variables loaded from .env
#14 2.070 Prisma schema loaded from prisma/schema.prisma
#14 3.659 [1/4] Resolving packages...
#14 4.129 [2/4] Fetching packages...
#14 5.198 info fsevents@2.3.2: The platform "linux" is incompatible with this module.
#14 5.198 info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
#14 5.230 [3/4] Linking dependencies...
#14 8.626 [4/4] Building fresh packages...
#14 8.799 success Saved 0 new dependencies.
#14 9.336 [1/4] Resolving packages...
#14 9.845 [2/4] Fetching packages...
#14 10.86 info fsevents@2.3.2: The platform "linux" is incompatible with this module.
#14 10.86 info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
#14 10.89 [3/4] Linking dependencies...
#14 14.33 [4/4] Building fresh packages...
#14 14.53 success Saved 0 new dependencies.
#14 14.62 Error: Could not resolve @prisma/client despite the installation that we just tried.
#14 14.62 Please try to install it by hand with npm install @prisma/client and rerun yarn prisma generate :pray:.
#14 14.65 error Command failed with exit code 1.
#14 14.65 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Unlike OP, switching the final command to

RUN dotenv -e .env.development -- yarn prisma

works just fine as part of the docker build, but will fail down the line when trying to boot for the reason of having not initialized