prisma: Query engine library for current platform "linux-musl" could not be found in Docker
Whenever I try to run my docker container on AWS App Runner I get the following:
When running my docker container locally it just works. I’m running the docker on AWS on amd64, while on my laptop it’s arm64 (m1 mac).
# Base
FROM --platform=linux/amd64 app/base:latest as base
# Build
FROM --platform=linux/amd64 node:18-alpine as api-builder
WORKDIR /usr/src/app
RUN apk add --no-cache libc6-compat
RUN apk update
RUN npm install -g turbo
COPY --from=base /usr/src/app /usr/src/app/
RUN turbo prune --scope=@app/api --docker
# Production image
FROM --platform=linux/amd64 node:18-alpine as api-runner
WORKDIR /usr/src/app
RUN apk add --no-cache libc6-compat
RUN apk add --update --no-cache openssl1.1-compat
RUN apk update
RUN npm install -g pnpm@7.17.0
RUN npm install -g npkill
COPY --from=api-builder /usr/src/app/out/pnpm*.yaml ./
COPY --from=api-builder /usr/src/app/out/json .
RUN pnpm install --frozen-lockfile
COPY --from=api-builder /usr/src/app/out/full .
RUN pnpm turbo run db:generate
RUN pnpm turbo run build --filter=@app/api...
RUN npkill
RUN pnpm install --offline --prod
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 runner
RUN chown -R runner:nodejs ./apps/api/build
USER runner
WORKDIR /usr/src/app/apps/api
ENTRYPOINT [ "node", "build/server.js" ]
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 28 (6 by maintainers)
Commits related to this issue
- fixes for projects using prisma orm (#497) We may remove these fixes in future and allow developers to resolve these issues themselves through custom docker files. For now though, they have no impa... — committed to nitrictech/cli by jyecusch 4 years ago
- fix(Docker): Changed alpine3.18 -> alpine3.16 According to https://github.com/prisma/prisma/issues/16901#issuecomment-1358121682 prisma works only in alpine-3.16 versions — committed to e-Learning-by-SSE/nm-self-learning by Elscha 2 years ago
- fix(Docker): Changed alpine3.18 -> alpine3.16 According to https://github.com/prisma/prisma/issues/16901#issuecomment-1358121682 prisma works only in alpine-3.16 versions — committed to spark-sse/nm-self-learning by Elscha 2 years ago
Closing this as the issue has a clear solution here. Currently, Prisma Client might not work out of the box with some bundlers, if you encounter such a case, please create an issue, as we want to improve on this area.
I’ve removed my path aliases for now to work around that. It seems to be working now 🙏
I think it still might be a good thing to have troubleshooting somewhere in the docs with a few steps people can try? Small list I came up with from this issue and related issues:
I think that will save you guys a lot of new issues related to this topic 😅
For me you can close this issue!
After circling on this page for 3+ hours, for anyone using nextjs, this solved my issues
At
schema.prismafile add:After that, run
npx prisma generateI was able to resolve this after a bit of poking around. More info below.
Was getting this error after a
docker run(it built fine):Some info on my local setup:
3.6.0Build command is:
Dockerfileis:Dockerfile
To fix, had to specify the
engineTypeto myprisma/schema.prisma:See https://www.prisma.io/docs/concepts/components/prisma-engines/query-engine#configuring-the-query-engine
FWIW, I ran into this problem running docker-compose locally with
node:16-alpine. Thanks @barryhagan for pointing out the changes to latest Alpine. I decided to bump to 18 but pin to 3.16 as you suggested:node:18-alpine3.16That worked for me.TL;DR
I did some more research, and to me it seems that it’s looking for the ‘query engine library’ in the wrong location.
Context
I use a
pnpmworkspace withturbo. At first I noticed when opening a terminal in the docker, not everything was there. For example on my local machine I have@prismain the rootnode_modules, but because of the prune (I think) it wasn’t there.Next I tried building the docker without pruning, and the binary engine was there in the root
node_modulesforlinux-musl-openssl3.x.so.node. However I found it in the@prisma/enginesfolder, while when believing the message it’s not looking there.These are the places Prisma look:
The location I’m referring to when I mean
@prisma/engines, I mean this one:/usr/src/app/node_modules/.pnpm/@prisma+client@4.8.0_prisma@4.8.0/node_modules/@prisma/clientWhen I physically check in terminal inside the docker I can find the engine lib but it’s not at that location, it’s here:
/usr/src/app/node_modules/.pnpm/@prisma+client@4.8.0_prisma@4.8.0/node_modules/@prisma/enginesBut it’s not looking there.
When diving deeper into these engine locations, I found an environment variable that can be set for where to find each binary, including the missing
libquerythe error is about (as far as I can understand). Find the docs here.I found the environment variable
PRISMA_QUERY_ENGINE_LIBRARYthat you can set to specify the ‘query engine library’ location. I understand correctly, this should normally only be used when you download or build these binaries yourself, not for the “auto downloaded” engines by Prisma.Though I tried setting it to
/usr/src/app/node_modules/.pnpm/@prisma+client@4.8.0_prisma@4.8.0/node_modules/@prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.nodeto match the exact location of where I found the binary when looking into the docker with the terminal.Now I’m stuck again. I’ve set the environment variable, double checked it’s effectively set, but still it doesn’t seem to look at that location. Maybe it does, but at least the issue remains the same, and the location of the environment variable isn’t added to the list Prisma prints out where it’s looking.
EDIT:
In the meantime I also tried adding a symbolic link that points the first location where Prisma looks
/usr/src/app/apps/api/build/libquery_engine-linux-musl-openssl-3.0.x.so.nodeto the above location in the@prisma/enginesfolder.node:20.18.1-alpine3.20 include OpenSSL https://hub.docker.com/layers/library/node/20.18.1-alpine3.20/images/sha256-a4041de87d5523532fa7081efda171fb0ef2046dec04bd9f0cf28d790c76e4fa
@gabo71096 if it helps, yarn version 4 has config options for
oswhich you can tweak the pull the Windows and Linux binaries.In my situation, I checked the node_modules/.prisma/client folder and I realized that I had a windows .dll instead of the
libquery_engine-debian-openssl-3.0.x.so.nodefile, I think it was caused because I runyarn prisma generateoutside of the container, and then the app went insane. Apparently running theprisma generatecommand manually, ignored the binaryTargets, and replaced the file with a windows option. After removing the folder node_modules, runningyarnagain on the host, and rebuilding the container, it finally worked.Adding below line in
schema.prismaworked like a charm.binaryTargets = ["native", "linux-musl-openssl-3.0.x"]I had the same problem and struggled with it for a day. I want to share my experience with those looking for a solution if their setup is like mine. I’m using
Turborepo, and I keep myPrismain its related package as theTurborepodocumentation suggests.I tried to bundle my app using
tsup, first I got an issue with finding the schema file, then after copying it to my build folder, I got the query engine platform error. by settingskipNodeModulesBundle: trueintsupconfig my problem has been solved.@jkomyno no worries, anything to help 😄
I think it might simply be fixed by not using
bundle: trueinesbuild.ts. At least, I got the repro working by doing that (and removing the postBuild hook). Testing my application again at the moment.I was just able to reproduce it also outside of Docker, however it might be related to my build step and there is no “actual” prisma issue related to the engine not being found, but rather a very confusing error message.
I’ve pushed my reproduction (built on @jkomyno’s proposed repro) to github: https://github.com/jclaessens97/prisma-repro
My guess is that when building with esbuild (I also have to add the postBuild step to place the schema in my build folder, otherwise it’s complaining it can’t find the schema), that some files are getting moved around (or not) and that it tries to reach some nescessary files using some sort of relative path.
However, I’m not sure which files, where I’m going wrong and how to fix it. On the other side if this IS the case (still not 100%), then I think Prisma can benefit from more clearer error messages 😄
EDIT: added expected repro output
Hi, thanks for your answer. I’ve tried the solutions proposed in the tagged discussion. First I got indeed an error about openSSL, but after I tried both
node:18-alpine3.16and installingapk add openssl1.1-compatand even usingnode:18-busterandnode:18, I still get the same errors.Even after explicity specifying the binaryTargets it keeps throwing errors.
Not sure if it’s still related to that openSSL package, or something else is wrong here.
I also have to note that I saw somewhere that installing
libc6-compatcan cause unexpected behaviour, but I need it installed to maketurbowork under alpine.Change
node:18-alpinetonode:18-alpine3.16in your dockerfile for now.Alpine 3.17 moved to OpenSSL 3.0 and that is now the tagged version for
18-alpine.Alternatively, install the openssl1.1-compat package with 3.17.
Prisma on Alpine w/ OpenSSL 3.0 is not ready yet: https://github.com/prisma/prisma/issues/16553