これは何?
AWS CodeBuildを使用して、Reactのソースコードをビルドしていた。エラーが発生したため、その対処方法のメモ。
前提
ランタイム Node.js: 18
Tips
- error
[Container] 2024/04/17 01:24:29.689519 Running command n 18 && rm -rf /tmp/* installing : node-v18.20.2 mkdir : /usr/local/n/versions/node/18.20.2 fetch : https://nodejs.org/dist/v18.20.2/node-v18.20.2-linux-x64.tar.xz copying : node/18.20.2 node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node) node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node) /usr/local/bin/node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by /usr/local/bin/node) /usr/local/bin/node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /usr/local/bin/node) installed : (with npm ) [Container] 2024/04/17 01:24:48.910339 Moving to directory /codebuild/output/src3539160356/src [Container] 2024/04/17 01:24:48.913081 Unable to initialize cache download: no paths specified to be cached [Container] 2024/04/17 01:24:49.066400 Configuring ssm agent with target id: codebuild:833d9e9f-3cff-4ada-a5b6-064be6417e92 [Container] 2024/04/17 01:24:49.094250 Successfully updated ssm agent configuration [Container] 2024/04/17 01:24:49.094647 Registering with agent [Container] 2024/04/17 01:24:49.140702 Phases found in YAML: 3 [Container] 2024/04/17 01:24:49.140740 INSTALL: 1 commands [Container] 2024/04/17 01:24:49.140747 PRE_BUILD: 4 commands [Container] 2024/04/17 01:24:49.140751 BUILD: 5 commands [Container] 2024/04/17 01:24:49.141037 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED [Container] 2024/04/17 01:24:49.141056 Phase context status code: Message: [Container] 2024/04/17 01:24:49.225260 Entering phase INSTALL [Container] 2024/04/17 01:24:49.225864 Running command npm install -g pnpm node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node) node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node) [Container] 2024/04/17 01:24:49.234030 Command did not exit successfully npm install -g pnpm exit status 1 [Container] 2024/04/17 01:24:49.239405 Phase complete: INSTALL State: FAILED [Container] 2024/04/17 01:24:49.239422 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm install -g pnpm. Reason: exit status 1
GLIBC_2.27, GLIBC_2.28が見つからないとのこと。
Linux イメージのランタイムを確認すると、Amazon Linux 2 x86_64 standard:4.0
が設定されていたため、Amazon Linux 2023 x86_64 standard:5.0
に変更してエラーが解消されました。
参考: 使用可能なランタイム - AWS CodeBuild
- 補足 GLIBCとはなにか?
- GNUプロジェクトにおけるCの標準ライブラリらしいです。Linuxにおいても標準Cライブラリとして使われているらしいです。
- 参考 glibc | 日経クロステック(xTECH) / The GNU C Library - GNU Project - Free Software Foundation
なぜこのエラーが発生したのか?
- もともと、ローカルではNode18を使用していたが、buildspec.ymlのruntimeがnode16になっていた。
- どこかのタイミングでライブラリがアップデートされてバージョンの互換性がなくなってエラーが発生したと思われる。
- 今回はバージョンを開発環境に合わせる形で対応したが、同じような現象が今後も発生するだろうし、ライブラリのバージョンアップデートを行い開発環境のバージョンが上がった場合にこちらのバージョンを上げ忘れるみたいなことは出てくる気がするのでどのように管理していくのがいいんだろう🤔