初めに
Next.jsの環境構築をDockerで行いました。以下の手順で進めていて、docker compose build
を実行したときにエラーが起きたのでメモを残しておきます。
git clone
docker compose build
問題
Dockerビルドのプロセスで yarn install
を実行しようとしたときに問題が起きました。
ERROR [front 5/5] RUN yarn install
> [front 5/5] RUN yarn install:
2.015 yarn install v1.22.19
2.299 [1/4] Resolving packages...
2.807 [2/4] Fetching packages...
67.47 info There appears to be trouble with your network connection. Retrying...
92.78 info There appears to be trouble with your network connection. Retrying...
105.9 info There appears to be trouble with your network connection. Retrying...
126.2 info There appears to be trouble with your network connection. Retrying...
139.0 info There appears to be trouble with your network connection. Retrying...
159.3 info There appears to be trouble with your network connection. Retrying...
172.6 info There appears to be trouble with your network connection. Retrying...
192.8 info There appears to be trouble with your network connection. Retrying...
213.3 info If you think this is a bug, please open a bug report with the information provided in "/opt/app/yarn-error.log".
213.3 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
213.3 error An unexpected error occurred: "https://registry.yarnpkg.com/@mui/icons-material/-/icons-material-5.14.11.tgz: ESOCKETTIMEDOUT"
222.5 info There appears to be trouble with your network connection. Retrying...
原因
ネットワーク接続に問題があり、何度もアクセスを試みていました。着目していただきたいのが、以下エラーの内容です。@mui/icons-material/-/icons-material-5.14.11.tgz
というパッケージのダウンロード時にESOCKETTIMEDOUT(ソケットタイムアウト)エラーが発生しています。これがインストール失敗の原因であることが分かります。
error An unexpected error occurred:
"https://registry.yarnpkg.com/@mui/icons-material/-/icons-material-5.14.11.tgz: ESOCKETTIMEDOUT"
解決方法
.yarnrc
ファイルをプロジェクトのルートディレクトリに作成して、以下設定を記述します。タイムアウトの時間を10分に変更して、タイムアウトによるエラーを回避することができました。今回は、@mui/icons-material/-/icons-material-5.14.11.tgz
という大きなパッケージをインストールするのに時間が掛かっていました。
network-timeout 600000
終わりに
yarn install
はプロジェクトに必要な依存パッケージをインターネットからダウンロードし、インストールするプロセスです。大きなパッケージを扱う場合、ネットワーク速度が遅い場合に時間が掛かるみたいです。その際は、タイムアウトの時間をさらに延ばして、回避できそうです。