Closed9

Prisma Clientが急に動かなくなった

gtcagtca

GitHub ActionsでCloud Buildを介してnode:18-alpineをベースイメージとしたDockerイメージ上でNext.jsアプリケーションをビルドしているが、今日突然Prisma Clientが動かない事象に遭遇した。
ビルド自体は成功して、デプロイも成功するが、DBからデータをとってこられない。

gtcagtca

実行時にこんな感じのエラー。

Unable to require(/app/node_modules/.prisma/client/libquery_engine-linux-musl.so.node). The Prisma engines do not seem to be compatible with your system. Please refer to the documentation about Prisma's system requirements: https://pris.ly/d/system-requirements Details: Error loading shared library libssl.so.1.1: No such file or directory (needed by /app/node_modules/.prisma/client/libquery_engine-linux-musl.so.node)

gtcagtca

GiHub Actionsのログを見てみるとwarningが出ていた。npx prisma generate の部分で以下のwarning。

prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".

加えて、yarn build の部分で以下のエラー(GitHub Actionsは落ちない)。

PrismaClientInitializationError: Unable to require(/app/node_modules/.prisma/client/libquery_engine-linux-musl.so.node).

gtcagtca

GitHub ActionsのUIの下の方にubuntu-latest pipelines will use ubuntu-24.04 soon.みたいな文言が出ていたので、GitHub ActionsのランタイムのUbuntuのバージョンが変わったせいかと思い、GitHub Actionsのワークフローファイルのruns-onの箇所を変更してみた。

- runs-on: ubuntu-latest
+ runs-on: ubuntu-22.04

が、特に変わらず。

gtcagtca

全く同じ症状のissueが2日前に立てられていた。node:18-alpine, node:20-alpineにopensslが入っていないのが原因っぽい。入っていないというかパスが変わったっぽい。node:18-alpineとかって環境が固定されているものだと思っていたけど、alpineのバージョンは変わり得るのか。知らなかった。3.20 → 3.21に変わったみたい。

https://github.com/prisma/prisma/issues/25817

https://github.com/nodejs/docker-node/issues/2175

issueのコメントにある通り、Dockerfileにシンボリックリンクを張るコマンドを入れてGitHub Actionsで出ていたwarningとエラーは解消。

RUN ln -s /usr/lib/libssl.so.3 /lib/libssl.so.3
gtcagtca

でも実行時はまだエラーが出る。

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

gtcagtca

エラーで言われた通りにgenerator clientにbinaryTargetsを追加する。

generator client {
   provider = “prisma-client-js”
+  binaryTargets = [“native”, “linux-musl”]
}

実行時に最初と同じエラーが出るようになった。うーん、いろいろやってるときにprismaのバージョンを6に上げてしまったのが良くなかった?

Unable to require(/app/node_modules/.prisma/client/libquery_engine-linux-musl.so.node). The Prisma engines do not seem to be compatible with your system. Please refer to the documentation about Prisma's system requirements: https://pris.ly/d/system-requirements Details: Error loading shared library libssl.so.1.1: No such file or directory (needed by /app/node_modules/.prisma/client/libquery_engine-linux-musl.so.node)

gtcagtca

prismaをダウングレード。

npm install --save-dev prisma@^5.0.0
npm install @prisma/client@^5.0.0

エラーは変わらず出る。

gtcagtca

やっぱりalpineのアップデートが全ての原因っぽいので、ベースイメージのalpineのバージョンを固定する。3.20にすれば大丈夫らしい。これまで変更した設定は全部元に戻した。

FROM node:20-alpine3.20 AS base

以前と同じようにうまく行くようになった。

このスクラップは2024/12/10にクローズされました