Read more

Fixing Yarn 1 error "unexpected end of file"

Henning Koch
January 12, 2023Software engineer at makandra GmbH

Our CI setup frequently sees this error while running yarn install:

yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
error An unexpected error occurred: " unexpected end of file".
info If you think this is a bug, please open a bug report with the information provided in "/builds/projects/foo-app/yarn-error.log".
info Visit for documentation about this command.
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show snapshot

This error is caused by Yarn not retrying npm disconnects Show snapshot which will not be fixed in Yarn 1 Show snapshot .

Assuming you don't want to upgrade to Yarn 2 Show snapshot , here are some workarounds for Yarn 1.

Increase Yarn's network timeout

yarn config set network-timeout 600000 -g

Retry yarn install until it succeeds

The following will retry yarn install up to 5 times or until it succeeds.

yarn || yarn || yarn || yarn || yarn
Posted by Henning Koch to makandra dev (2023-01-12 15:41)