Solution for debugging EAS cloud builds is similar to what I do when I need to debug GitHub runners, I ssh to the cloud runner.

There are various reasons for failing the eas cloud build - missing environment variables, improperly set environment variables, missing permissions, missing dependencies etc.

EAS Cloud builds can be costly, a single build costs 1$ per android and 2$ per ios build.

Just looking at the failed logs doesn't always help me. So I thought, why not use the same technique that I use with GitHub, and just ssh to the EAS cloud runner?

I do that with the help of tmate and eas preinstall hooks.

eas-build-pre-install

Hook that gets executed on EAS before npm install is run. Add it by declaring it in the package.json scripts:

  "scripts": {
    "eas-build-pre-install": "scripts/eas-build-pre-install.sh"
  }

package.json

Create scripts/eas-build-pre-install.sh and mark it executable (chmod +x).

#!/bin/bash

cd "$(dirname "$0")/.." || exit 1
echo "Running script from $(pwd)"

set -e

if [ "$EAS_BUILD" = "true" ]; then
  echo "Running in EAS cloud build environment."
  if [ "$EAS_BUILD_PLATFORM" = "android" ]; then
    sudo apt install -y tmate
  elif [ "$EAS_BUILD_PLATFORM" = "ios" ]; then
    NONINTERACTIVE=1
    brew install tmate
  fi
  echo "Running tmate debug session"
  bash ./scripts/tmate-debug.sh
fi

echo "Finished preinstall script"

eas-build-pre-install.sh

First 3 lines make sure that location from where script is executed doesn't matter and in case of any non-zero status, script exits immediately.

If clause makes sure this script is only executed on eas cloud, otherwise this would get called on your local machine every time.

The commented part is there on purpose, tmate debug script should be executed with caution. Runner will not continue, as long as the tmate ssh session is running.

When tmate session is finished, eas continues with rest of the steps.

tmate-debug.sh

Script should be marked as executable. The part that initiates a remote ssh session:

#!/bin/bash

set -e

echo "Setting up tmate debug session..."

tmate -S /tmp/tmate.sock new-session -d
tmate -S /tmp/tmate.sock wait tmate-ready

echo "SSH connection:"
tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}'
echo "Web connection:"
tmate -S /tmp/tmate.sock display -p '#{tmate_web}'

echo "Waiting for user to disconnect (type 'exit' in SSH)..."
tmate -S /tmp/tmate.sock wait tmate-exit

tmate-debug.sh

Starts a new tmate session in the background using a socket file, you'll see the link to ssh in the log of the cloud runner. When you're done, just type exit. The build will then continue.

If you want to see this in action, take a look at my YouTube video.