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)
This happened to me because I only had
@prisma/client
installed, and I needed to also installprisma
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)
I had this problem, because i didn’t install prisma in my project. lmao.
My problem was solved by moving
prisma
fromdevDependenies
todepenencies
. The fact is that when installing my library from npm,prisma
was not installed because it was indevDependenies
andprisma generate
was launched from a package that is higher in the folder hierarchy than the project root, this caused error:yeah the
prisma
must be also installed, especially when usingpnpm
(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!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.jsonResolved by
yarn add prisma
for meFixed 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
in the same package.json where
prisma generate
fails but this shouldn’t affect the generation?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:
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
Output
Unlike OP, switching the final command to
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