Fixing Yarn ESOCKETTIMEDOUT Error During Discourse Setup

While installing Discourse on a free tier instance in a Google Cloud Compute Instance, I was following this discourse install tutorial with only minor adjustments:

  • Used Ubuntu 20.04 LTS minimal
  • Standard Disk (default is Balanced)
  • e2.micro instance

However, when I was waiting for Step 9 to complete (after running ./discourse-setup) and everything being built, it would fail with an ESOCKETTIMEDOUT error related to yarn. The last message that tries to run is [ ! -d 'node_modules' ] || su discourse -c 'yarn install --production && yarn cache clean'.

Here’s what is going wrong. Yarn has a default timeout that is fine if you are using the minimum recommended for Discourse, but with a micro instance, it takes too long. To fix this, you have to manually edit one of the install scripts that runs for the new Docker container Discourse is building.

The Fix

You need to install an editor; I prefer nano so apt-get install nano does the trick. Then go to /var/discourse/templates and run: nano web.template.yml. For comparison, here is the file you cloned from github and the area of interest is around line 159. Look familiar? It’s the same command noted above before it failed. We need to add a new section above this line to increase the timeout.

  - exec:
      cd: $home
        - "su discourse -c 'yarn config set network-timeout 600000 -g'"

Save this change then rerun ./discourse-setup and viola, completion! It will definitely take a while, especially the brotli compression step, but it will finish.

One thought on “Fixing Yarn ESOCKETTIMEDOUT Error During Discourse Setup

Leave a Reply

Your email address will not be published. Required fields are marked *