LoginSignup
45
24

More than 1 year has passed since last update.

【Tips】yarn install時に発生しうるESOCKETTIMEDOUTの回避

Last updated at Posted at 2019-09-17

問題:yarn installの失敗

入力

yarnでパッケージ管理を行っているディレクトリ(フォルダ)において、

yarn install

を実行すると、下記のようにESOCKETTIMEDOUTのエラーが発生し正常にインストールできない場合がある。

出力

[1/5]   Validating package.json...
[2/5]   Resolving packages...
[3/5]   Fetching packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.yarnpkg.com/material-design-icons/-/material-design-icons-3.0.1.tgz: ESOCKETTIMEDOUT".
info If you think this is a bug, please open a bug report with the information provided in "【yarn-error.logのあるディレクトリへのパス】".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

環境:WSL下のUbuntu

  • Windows 10 Home 1903
    • Windows Subsystem for Linux によりLinux環境を利用
  • Ubuntu 18.04.3 LTS (Bionic Beaver)
  • anyenv
    • nodenv
      • node v10.15.3
      • yarn 1.17.3

原因:ダウンロードのタイムアウト(時間切れ)

巨大ファイル(上記の例ではmaterial-design-icons-3.0.1.tgz)のダウンロードに時間がかかりすぎたことによって、ネットワークが正しくつながってないと誤認されインストールが途中で中断されている。

解決方法:設定ファイルを配置しダウンロード時間を設定

yarn installを行うディレクトリに.yarnrcという名前のファイルを作り、以下の内容を記述する。すでにある場合は末尾に追記、または該当する行の編集を行う。これによりタイムアウトの待ち時間が10分になるため多くの場合はダウンロードに成功し処理が進む。

.yarnrc
network-timeout 600000

network-timeoutの項目に書かれた時間だけダウンロードの時間を待ってくれる。ミリ秒指定のため「書かれている数字÷1000」が実際の待ち時間秒数。上記では60万ミリ=6000秒=10分のダウンロード時間を設定している。

補足

遅いネットワークを利用している環境では10分でも足りない場合がある。その際は適宜設定ファイル.yarnrcnetwork-timeoutに書かれている数字を大きくする。

参考文献

45
24
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
45
24