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 3 years ago
  • Reactions: 14
  • Comments: 42 (7 by maintainers)

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.

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

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

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

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

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

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

I love you, I really do

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

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

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

Resolved by yarn add prisma for me

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