Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__res_init: symbol not found when running Prisma #14043

Closed
cmwhited opened this issue Jun 28, 2022 · 27 comments
Closed

__res_init: symbol not found when running Prisma #14043

cmwhited opened this issue Jun 28, 2022 · 27 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: alpine topic: docker topic: node version topic: openssl

Comments

@cmwhited
Copy link

What error exactly @cmwhited? Can you try with a prisma@dev and @prisma/client@dev (or version 4.0.0 which will be release tomorrow) please and post the full output you are getting? That would help us to make sure you ar egetting the same error indeed.

Updated to v4.0.0 and it still fails. I think it is actually an issue with pnpm. Testing now

update

after upgrading to v4, it is now throwing this more verbose error

#21 2.546 Error: Get Config: Unable to establish a connection to query-engine-node-api library. It seems there is a problem with your OpenSSL installation!
#21 2.546 Details: Unable to require(`/app/node_modules/.pnpm/prisma@4.0.0/node_modules/prisma/libquery_engine-linux-arm64-openssl-1.1.x.so.node`)
#21 2.546  Error relocating /app/node_modules/.pnpm/prisma@4.0.0/node_modules/prisma/libquery_engine-linux-arm64-openssl-1.1.x.so.node: __res_init: symbol not found

update 2

Switching from pnpm to yarn does not solve the issue, throws error

#18 1.179 api:gen:types: Prisma schema loaded from prisma/schema.prisma
#18 1.419 api:gen:types: Error: Get Config: Unable to establish a connection to query-engine-node-api library. It seems there is a problem with your OpenSSL installation!
#18 1.421 api:gen:types: Details: Unable to require(`/app/node_modules/prisma/libquery_engine-linux-arm64-openssl-1.1.x.so.node`)
#18 1.421 api:gen:types:  Error relocating /app/node_modules/prisma/libquery_engine-linux-arm64-openssl-1.1.x.so.node: __res_init: symbol not found
#18 1.421 api:gen:types: 
#18 1.421 api:gen:types: Prisma CLI Version : 4.0.0
#18 1.438 api:gen:types: error Command failed with exit code 1.

idk if it helps, but here are my versions

  • nodejs: v16.15.0
  • yarn: v1.22.17
  • pnpm: v7.3.0
  • mac osx: v12.4, m1 chip
  • docker: version 20.10.16, build aa7e414

Originally posted by @cmwhited in #13717 (comment)

@cmwhited
Copy link
Author

Follow up question 1 (please reply in new issue): Does /app/node_modules/prisma/libquery_engine-linux-arm64-openssl-1.1.x.so.node exist?

it does not exist @janpio

Screen Shot 2022-06-28 at 12 30 59 PM

@janpio
Copy link
Member

janpio commented Jun 28, 2022

Earlier, additional information from @cmwhited on his system: #13717 (comment)

I am also getting this error when running prisma generate though docker using the FROM node:16.15-alpine3.16 image and installing openssl through apk:

FROM node:16.15-alpine3.16
RUN apk add --no-cache git curl python3 make gcc libc-dev g++ libc6-compat openssl openssl-dev \
    && curl -sL https://unpkg.com/@pnpm/self-installer[](https://unpkg.com/@pnpm/self-installer) | node
RUN ln -sf python3 /usr/bin/python

Here is my example repo

@jkomyno
Copy link
Contributor

jkomyno commented Jun 29, 2022

This is probably a duplicate of #9572. More details will follow

@pimeys pimeys added the team/client Issue for team Client. label Jun 29, 2022
jkomyno added a commit to jkomyno/reproduce-issue-14043 that referenced this issue Jun 29, 2022
@pimeys pimeys added kind/bug A reported bug. bug/2-confirmed Bug has been reproduced and confirmed. labels Jun 29, 2022
@cmwhited
Copy link
Author

@jkomyno @janpio I went down the path as referenced here: #8478 (comment)

and updated my Dockerfile to

FROM positivly/prisma-binaries:latest as prisma
FROM node:16.15-alpine3.16
RUN apk add --no-cache git curl python3 make gcc libc-dev g++ libc6-compat openssl openssl-dev \
    && curl -sL https://unpkg.com/@pnpm/self-installer | node
RUN ln -sf python3 /usr/bin/python
COPY --from=prisma /prisma-engines/query-engine /prisma-engines/migration-engine /prisma-engines/
ENV PRISMA_QUERY_ENGINE_BINARY=/prisma-engines/query-engine \
  PRISMA_MIGRATION_ENGINE_BINARY=/prisma-engines/migration-engine \
  PRISMA_CLI_QUERY_ENGINE_TYPE=binary \
  PRISMA_CLIENT_ENGINE_TYPE=binary

WORKDIR /app

EXPOSE 4000/tcp

ARG DATABASE_URL

ENV DATABASE_URL=${DATABASE_URL}

COPY ./package.json /app/package.json
COPY ./pnpm-workspace.yaml /app/pnpm-workspace.yaml
COPY ./turbo.json   /app/turbo.json
COPY ./apps/api/package.json  /app/apps/api/package.json
COPY ./apps/api/prisma/schema.prisma /app/apps/api/prisma/schema.prisma
COPY ./pnpm-lock.yaml /app/pnpm-lock.yaml

# install the packages

COPY . .

# build .env in /app/apps/api

RUN cd /app/apps/api \
  && touch .env \
  && echo "DATABASE_URL=${DATABASE_URL}" >> .env \
  && cat .env

RUN --mount=type=secret,id=npmrc,dst=/root/.npmrc \
  pnpm i --prod false

RUN pnpm gen:types:api

RUN pnpm build

This fails with a lovely new error:

#23 1.132 api:gen:types: > prisma generate
#23 1.132 api:gen:types: 
#23 1.574 api:gen:types: Environment variables loaded from .env
#23 1.576 api:gen:types: Prisma schema loaded from prisma/schema.prisma
#23 1.946 api:gen:types: Error: 
#23 1.946 api:gen:types: TypeError: collection is not iterable
#23 1.946 api:gen:types:     at keyBy (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:60084:21)
#23 1.946 api:gen:types:     at DMMFDatamodelHelper.getTypeMap (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:61890:17)
#23 1.946 api:gen:types:     at new DMMFDatamodelHelper (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:61880:25)
#23 1.946 api:gen:types:     at new BaseDMMFHelper (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:62031:32)
#23 1.946 api:gen:types:     at new DMMFHelper (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:62038:32)
#23 1.946 api:gen:types:     at new TSClient (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:63260:17)
#23 1.946 api:gen:types:     at buildClient (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:63525:24)
#23 1.946 api:gen:types:     at generateClient (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:63592:47)
#23 1.946 api:gen:types:     at async LineStream.<anonymous> (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:56452:24)
#23 1.946 api:gen:types: 
#23 1.946 api:gen:types: 
#23 1.961 api:gen:types:  ELIFECYCLE  Command failed with exit code 1.
#23 1.976 api:gen:types: ERROR: command finished with error: command (apps/api) pnpm run gen:types exited (1)
#23 1.976 command (apps/api) pnpm run gen:types exited (1)

Going to issue #9572 lead me to there

jkomyno added a commit to jkomyno/reproduce-issue-14043 that referenced this issue Jul 1, 2022
@janpio
Copy link
Member

janpio commented Jul 1, 2022

Quick side note @cmwhited: Our error message It seems there is a problem with your OpenSSL installation! is definitely wrong and misleading here. The problem is most probably that we do not have the correct engine file for your environment, or Prisma does not correctly detect that, see: #8478

@cmwhited
Copy link
Author

Quick side note @cmwhited: Our error message It seems there is a problem with your OpenSSL installation! is definitely wrong and misleading here. The problem is most probably that we do not have the correct engine file for your environment, or Prisma does not correctly detect that, see: #8478

I added:

binaryTargets = ["native", "linux-arm64-openssl-1.1.x"]

to the schema.prisma which I can see generates the correct engine file, but I still get the

#23 1.576 api:gen:types: Prisma schema loaded from prisma/schema.prisma
#23 1.946 api:gen:types: Error: 
#23 1.946 api:gen:types: TypeError: collection is not iterable
#23 1.946 api:gen:types:     at keyBy (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:60084:21)
#23 1.946 api:gen:types:     at DMMFDatamodelHelper.getTypeMap (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:61890:17)
#23 1.946 api:gen:types:     at new DMMFDatamodelHelper (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:61880:25)
#23 1.946 api:gen:types:     at new BaseDMMFHelper (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:62031:32)
#23 1.946 api:gen:types:     at new DMMFHelper (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:62038:32)
#23 1.946 api:gen:types:     at new TSClient (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:63260:17)
#23 1.946 api:gen:types:     at buildClient (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:63525:24)
#23 1.946 api:gen:types:     at generateClient (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:63592:47)
#23 1.946 api:gen:types:     at async LineStream.<anonymous> (/app/node_modules/.pnpm/@prisma+client@4.0.0_prisma@4.0.0/node_modules/@prisma/client/generator-build/index.js:56452:24)
#23 1.946 api:gen:types: 

error

@cmwhited
Copy link
Author

@janpio switching docker to the 16.15-slim image does work. So it is an xx-alpine docker image issue

@TeemuKoivisto
Copy link

@janpio switching docker to the 16.15-slim image does work. So it is an xx-alpine docker image issue

Yeah somebody should definitely put up somewhere that installing Prisma on alpine crashes with these most bizarre error messages. Switching to slim and adding RUN apt-get update && apt-get -y install openssl fixed this for me.

@bmxpiku
Copy link

bmxpiku commented Sep 27, 2022

I'm using node:18-alpine, upgraded from prisma 3.14 to 4.3.1 and now I experience the same issue...

PS: I'm not running this via compose - but deploy image to AWS ECS (fargate) and it doesn't want to work there

@nassim-kachroud
Copy link

Same issue on my side using prisma 4.x.x, any update?

@DavorJ94
Copy link

DavorJ94 commented Dec 13, 2022

@nassim-kachroud @bmxpiku maybe try with this in your alpine container as soon as you pull initial image, it solved for me:

    apk add openssl && \
    apk add openssl-dev && \
    apk add libc6-compat && \
    rm -rf /var/cache/apk/*

@vuong-nguyen-saltovn
Copy link

vuong-nguyen-saltovn commented Dec 13, 2022

"prisma": "3.14.0"
"node": "14.21.1"
"@prisma/client": "3.14.0"
"@nestjs/core": "^9.2.0"
"typescript": "^4.3.5"

$ prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Error: Unable to require(`/backend/node_modules/prisma/libquery_engine-linux-musl.so.node`)
 Error loading shared library libssl.so.1.1: No such file or directory (needed by /backend/node_modules/prisma/libquery_engine-linux-musl.so.node)

I got this error when build in docker, too.

@senorscan
Copy link

Same issue, I tried with your suggestion @DavorJ94, however still no luck. Tried 16.15-slim and it's working. Must have been some regression in the latest version of 16-alpine

@DavorJ94
Copy link

@senorscan Interesting, it works for me for 16.12-alpine, but for 18 it won't work. It seems there really is some regression. Maybe you can try 16.12.

@vuong-nguyen-saltovn
Copy link

@senorscan Interesting, it works for me for 16.12-alpine, but for 18 it won't work. It seems there really is some regression. Maybe you can try 16.12.

It worked! Thank you very much.

@edlundin
Copy link

I had the same issue with the docker image node:19-alpine, but using node:19-alpine3.16 fixed it.

Could it be an issue with alpine 3.17?
Quoting https://alpinelinux.org/posts/Alpine-3.17.0-released.html, the default OpenSSL version, starting from 3.17, is 3.0. To use OpenSSL 1.1, installing the package openssl1.1-compat seems necessary.

@zackdotcomputer
Copy link

Thanks @edlundin - that unblocked me. Adding RUN apk add --update --no-cache openssl1.1-compat to my dockerfile has fixed builds without needing to resort to the downgrade/crossgrade/emulation solutions on other threads.

@valentinpezon-primo
Copy link

Hey, just had this exact issue, thanks for the solution.

@zackdotcomputer, so you added RUN apk add --update --no-cache openssl1.1-compat and kept node:lts-alpine ?

@zackdotcomputer
Copy link

@valentinpezon-primo In my case I'm on node:fermium-alpine still but yes to the rest. Just needed to be sure to add the apk command before the npm install command because of the prisma post-install hook.

@DavorJ94
Copy link

@valentinpezon-primo yes, I just tried it with node:18.12-alpine, it seems to work for any version. Perfect, thanks.

@maitrungduc1410
Copy link

maitrungduc1410 commented Dec 13, 2022

weird, it was working fine for months, and just from this morning it has been failing in my Gitlab CI, building manually from local is fine. No change from my Dockerfile at all.

Adding this before npm install fixed the issue:

RUN apk add --update --no-cache openssl1.1-compat

Update: build success with the above change, but at runtime , it throw error:

  | Unable to load Node-API Library from /app/node_modules/.prisma/client/libquery_engine-linux-musl.so.node, Library may be corrupt
  |     at RequestHandler.handleRequestError (/app/node_modules/@prisma/client/runtime/index.js:30879:13)
  |     at /app/node_modules/@prisma/client/runtime/index.js:31300:25
  |     at processTicksAndRejections (node:internal/process/task_queues:96:5)
  |     at async PrismaClient._executeRequest (/app/node_modules/@prisma/client/runtime/index.js:31864:22) {
  |   clientVersion: '4.5.0',
  |   errorCode: undefined
  | }

@ugurkellecioglu
Copy link

ugurkellecioglu commented Dec 13, 2022

I specified the node version as "node:alpine" in my Dockerfile. I switched it to 16.2 and now it works fine.

@rained23
Copy link

getting this issue in my bitbucket pipelines too

@Maetes
Copy link

Maetes commented Dec 14, 2022

weird, it was working fine for months, and just from this morning it has been failing in my Gitlab CI, building manually from local is fine. No change from my Dockerfile at all.

Adding this before npm install fixed the issue:

RUN apk add --update --no-cache openssl1.1-compat

When I Add this line I can build the Docker-file but I get the error:

In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues

it is related to OpenSSL as @edlundin already said. Prisma only supports 1.X instead of 3.0 which is now default in the alpine builds >3.16

see also this issue
#16553

@Geczy
Copy link

Geczy commented Dec 15, 2022

fixed as well by switching to FROM node:16.2.0-alpine AS deps

@jkomyno
Copy link
Contributor

jkomyno commented Dec 15, 2022

Hey, Alberto from Prisma here.

For people facing this issue on Linux Alpine (e.g., when using the node:alpine, node:lts-alpine Docker images), please refer to this solution: #16553 (comment)

@jkomyno jkomyno changed the title Unable to require(/app/node_modules/prisma/libquery_engine-linux-arm64-openssl-1.1.x.so.node) __res_init: symbol not found when running Prisma Dec 15, 2022
@jkomyno
Copy link
Contributor

jkomyno commented Feb 6, 2023

Closing as the issue is solved by #14043 (comment)

@jkomyno jkomyno closed this as completed Feb 6, 2023
Samox added a commit to OpenWebhook/webhook-store that referenced this issue Mar 16, 2023
Samox added a commit to OpenWebhook/webhook-store that referenced this issue Mar 16, 2023
* refactor: remove types package from dependencies

* fix: use node alpine 16.18.0 to fix prisma build error
prisma/prisma#14043
Samox added a commit to OpenWebhook/webhook-store that referenced this issue Mar 16, 2023
Samox added a commit to OpenWebhook/webhook-store that referenced this issue Mar 16, 2023
* feature: upgrade node version to 18
prisma/prisma#14043 (comment)

* docs: add a documentation for docker

* chore: upgrade prisma version

* chore: upgrade nest and gql version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: alpine topic: docker topic: node version topic: openssl
Projects
None yet
Development

No branches or pull requests