prisma: prisma fails to find openssl 3.0.x on new bookworm docker.io/node:lts-slim container image

Bug description

An application that is built on docker.io/node:lts (18.16.0-bookworm) fails to run on docker.io/node:lts-slim (18.16.0-bookworm-slim).

This was working previously on the node:18.16.0-bullseye images, node:18.16.0-bookworm-slim no longer includes libssl.

  prisma:client  checkPlatformCaching:postinstall false +169ms
  prisma:client  checkPlatformCaching:ciName undefined +1ms
  prisma:tryLoadEnv  Environment variables not found at null +169ms
  prisma:tryLoadEnv  Environment variables not found at undefined +0ms
  prisma:tryLoadEnv  No Environment variables loaded +0ms
  prisma:client  dirname /project/dist +168ms
  prisma:client  relativePath ../src/prisma +0ms
  prisma:client  cwd /project/dist +0ms
  prisma:client  protocol graphql +0ms
  prisma:client  clientVersion 4.15.0 +0ms
  prisma:client  clientEngineType library +0ms
  prisma:client:libraryEngine  internalSetup +168ms
  prisma:get-platform  Found distro info:
{
  "targetDistro": "debian",
  "familyDistro": "debian",
  "originalDistro": "debian"
} +0ms
  prisma:get-platform  Trying platform-specific paths for "debian" (and "ubuntu") +0ms
  prisma:get-platform  Found distro info:
{
  "targetDistro": "debian",
  "familyDistro": "debian",
  "originalDistro": "debian"
} +1ms
  prisma:get-platform  Trying platform-specific paths for "debian" (and "ubuntu") +0ms
  prisma:get-platform  Falling back to "ldconfig" and other generic paths +1ms
  prisma:get-platform  Falling back to "ldconfig" and other generic paths +10ms
  prisma:get-platform  Couldn't find any version of libssl or OpenSSL in the system +19ms
prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
Please manually install OpenSSL via `apt-get update -y && apt-get install -y openssl` and try installing Prisma again. If you're running Prisma on Docker, you may also try to replace your base image with `node:lts-slim`, which already ships with OpenSSL installed.
  prisma:client:engines:resolveEnginePath  enginePath undefined +0ms
Prisma Client could not locate the Query Engine for runtime "debian-openssl-1.1.x".

This happened because Prisma Client was generated for "debian-openssl-3.0.x", but the actual deployment required "debian-openssl-1.1.x".
Add "debian-openssl-1.1.x" to `binaryTargets` in the "schema.prisma" file and run `prisma generate` after saving it:

generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "debian-openssl-1.1.x"]
}

The following locations have been searched:
  /project/dist
  /project
  /builder/node_modules/@prisma/client
  /.prisma/client
  /tmp/prisma-engines {
  error: PrismaClientInitializationError: Prisma Client could not locate the Query Engine for runtime "debian-openssl-1.1.x".
  
  This happened because Prisma Client was generated for "debian-openssl-3.0.x", but the actual deployment required "debian-openssl-1.1.x".
  Add "debian-openssl-1.1.x" to `binaryTargets` in the "schema.prisma" file and run `prisma generate` after saving it:
  
  generator client {
    provider      = "prisma-client-js"
    binaryTargets = ["native", "debian-openssl-1.1.x"]
  }

The fix is the same as noted in the error messages (apt-get install openssl) but it would appear with the change to Debian 12/bookworm, the node:lts-slim image will no longer be a solution

How to reproduce

Expected behavior

No response

Prisma information

Any prisma, any app, multistage container build onto docker.io/node:lts-slim

FROM node:lts as build
WORKDIR /builder
COPY package.json package-lock.json /builder/
RUN npm install && npm build

FROM node:lts-slim
WORKDIR /project
COPY --from=build /builder/dist/. /project
RUN node /project/app.js

Environment & setup

  • OS: Debian
  • Database: Postgres
  • Node.js version: 18.16.0

Prisma Version

prisma                  : 4.15.0
@prisma/client          : 4.15.0
Current platform        : debian-openssl-3.0.x
Query Engine (Node-API) : libquery-engine 8fbc245156db7124f997f4cecdd8d1219e360944 (at ../../node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node)
Migration Engine        : migration-engine-cli 8fbc245156db7124f997f4cecdd8d1219e360944 (at ../../node_modules/@prisma/engines/migration-engine-debian-openssl-3.0.x)
Format Wasm             : @prisma/prisma-fmt-wasm 4.15.0-28.8fbc245156db7124f997f4cecdd8d1219e360944
Default Engines Hash    : 8fbc245156db7124f997f4cecdd8d1219e360944
Studio                  : 0.484.0
Preview Features        : postgresqlExtensions, views

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 21 (5 by maintainers)

Most upvoted comments

Solution! Specifying a version like node:20.1.0-alpine helps ensure that your builds are reproducible and secure. This prevents unexpected issues due to changes in the base image.

While using an image hash can also achieve this, it’s generally not recommended because it can make maintenance and updates more difficult.

For optimal security and maintainability, consider regularly rebuilding your images and potentially setting up automated builds to incorporate updates to both your application and the base image.

For everyone working on an Alpine based image, you need to install openssl with apk

RUN set -ex; \
    apk update; \
    apk add --no-cache \
    openssl

I solved the issue by installing openssl at the dockerfile

take a look at the command below is implemented for all the staging step

RUN apk add --no-cache openssl

check my dockerfile below

FROM node:20-alpine As development
WORKDIR /usr/src/app
RUN apk add --no-cache openssl
COPY --chown=node:node package*.json ./
RUN npm ci
COPY --chown=node:node . .
RUN npx prisma generate
USER node

FROM node:20-alpine As build
WORKDIR /usr/src/app
RUN apk add --no-cache openssl
COPY --chown=node:node package*.json ./
COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules
COPY --chown=node:node . .
RUN npm run build
ENV NODE_ENV production
RUN npm ci --only=production && npm cache clean --force
USER node

FROM node:20-alpine As production
RUN apk add --no-cache openssl
COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
COPY --chown=node:node --from=build /usr/src/app/dist ./dist
COPY --chown=node:node --from=build /usr/src/app/public ./public
CMD ["node", "dist/main.js"]

Follow me for more

As I’m iterating on this, one thing I realized is that, if you are doing multi-stage builds, make sure that your build container is on the same OS level as the run container. I made the mistake of using node:18 (which recently got updated to run on bookworm) as the builder, and using node:18-bullseye-slim as the runner. The result is that the build process builds libquery_engine-debian-openssl-3.0.x.so.node, which won’t work for node:18-bullseye-slim because that image still use and expects openssl 1.1.x

holyshit im experiencing this too. but prisma is looking for openssl 1.x in my case? running prisma ^4.11.0

Linux hostname 5.4.219-126.411.amzn2.x86_64 #1 SMP Wed Nov 2 17:44:17 UTC 2022 x86_64 GNU/Linux
libssl.so.1.1: cannot open shared object file: No such file or directory
    at Zr.handleRequestError (/usr/src/app/node_modules/@prisma/client/runtime/library.js:171:6414)
    at Zr.handleAndLogRequestError (/usr/src/app/node_modules/@prisma/client/runtime/library.js:171:5948)
    at /usr/src/app/node_modules/@prisma/client/runtime/library.js:174:3087
    at async /usr/src/app/node_modules/@prisma/client/runtime/library.js:174:3268

am currently reverting to old node docker build

Hi @mhio, you are facing this issue because node:lts-slim no longer ships with libssl installed as of June 10th 2023, when Debian Bookworm (the Linux distribution on which Node.js’ slim Docker images are based on) was released.

As Prisma needs OpenSSL to operate correctly, you can fix your Dockerfile as follows:

# syntax=docker/dockerfile:1
FROM node:lts-slim

RUN apt-get update -y
RUN apt-get install -y openssl

This should correctly install OpenSSL 3.x in your Docker image.

To those looking for a quick and temporary solution, reverting to node:18.15.0* works.

Today’s image push seems to cause this issue.

This can now be closed, thanks for reporting it 🙌🏼 . If you still experience an issue, let us know.

I think it could be interesting to surface this in our docs given the popularity of these Docker images.

I can recommend using a more specific tag than node:lts-slim - See all tags on https://hub.docker.com/_/node/

This change comes from the fact that

  • node:lts-slim used to be an alias for node:lts-bullseye-slim (based on Debian 11 bullseye)
  • node:lts-slim is now an alias for node:lts-bookworm-slim (based on Debian 12 bookworm)

Since the Node.js version can also impact apps, I usually prefer to specify the version too, example:

  • node:18-bookworm-slim
  • node:18-bullseye-slim

There are 2 different approaches to solve this issue here:

  • Like @jkomyno mentioned, in the slim version based on bookworm, OpenSSL is not provided anymore and needs to be installed additionally.
  • You can also keep using the slim version based on the previous Debian version, bullseye, example: node:18-bullseye-slim.

I can confirm @morpig’s advice. For the time being, let’s use node:18.15. I use the following:

FROM node:18.15-slim

Is there a way to have prisma throw an error in this situation? Maybe some sort of flag I can set? I’d prefer my build fail in this case and catch it early as opposed to at runtime. My issue was not pinning to a specific node alpine image version, but would like to prevent my build from succeeding in the future if prisma fails to detect the libssl/openssl version to use. If anyone has any suggestions it would be appreciated.

@Azleal Just add this to your dockerfile:

RUN set -ex; \
    apt-get update -y ; \
    apt-get install -y --no-install-recommends \
      openssl

Note, we improved the logs since 4.16.0 instead of

  prisma:get-platform  Couldn't find any version of libssl or OpenSSL in the system +19ms
prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
Please manually install OpenSSL via `apt-get update -y && apt-get install -y openssl` and try installing Prisma again. If you're running Prisma on Docker, you may also try to replace your base image with `node:lts-slim`, which already ships with OpenSSL installed.

It’s now fixed, we do not say to switch to node:lts-slim as it does not include openssl anymore. You can use node:lts-slim but you will need to add apt-get update -y && apt-get install -y openssl to your Dockerfile

  prisma:get-platform  Couldn't find any version of libssl or OpenSSL in the system +19ms
prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
Please manually install OpenSSL via `apt-get update -y && apt-get install -y openssl` and try installing Prisma again. If you're running Prisma on Docker, add this command to your Dockerfile, or switch to an image that already has OpenSSL installed.

facing the same issue as well on node:18-slim and node:lts-slim