Guides
Plan-enterprise-icon
Expo Application Services
API Reference

Build lifecycle hooks

There are five EAS Build lifecycle npm hooks that you can set in your package.json. See the Android build process and iOS build process docs to get a better understanding about the internals of the build process.
  • eas-build-pre-install - executed before EAS Build runs npm install.
  • eas-build-post-install - the behavior depends on the platform and project type:
    • Android - runs once after the following commands have all completed: npm install and npx expo prebuild (if needed)
    • iOS - runs once after the following commands have all completed: npm install, npx expo prebuild (if needed), and pod install.
  • eas-build-on-success - this hook is triggered at the end of the build process if the build was successful.
  • eas-build-on-error - this hook is triggered at the end of the build process if the build failed.
  • eas-build-on-complete - this hook is triggered at the end of the build process. You can check the build's status with the EAS_BUILD_STATUS environment variable. It's either finished or errored.
This is an example of how your package.json might look like:
package.json
{
  "name": "my-app",
  "scripts": {
    "eas-build-pre-install": "echo 123",
    "eas-build-post-install": "echo 456",
    "eas-build-on-success": "echo 789",
    "eas-build-on-error": "echo 012",
    "start": "expo start",
    "test": "jest"
  },
  "dependencies": {
    "expo": "~46.0.0"
    // ...
  }
}

Platform-specific hook behavior

If you would like to run a script (or some part of a script) only for iOS builds or only for Android builds, you can fork the behavior depending on the platform within the script. See examples for common ways to do this through a shell script or a Node script below.

Examples

package.json and shell script

package.json
{
  "name": "my-app",
  "scripts": {
    "eas-build-pre-install": "./pre-install",
    "start": "expo start"
    // ...
  },
  "dependencies": {
    // ...
  }
}
pre-install
#!/bin/bash

# This is a file called "pre-install" in the root of the project

if [[ "$EAS_BUILD_PLATFORM" == "android" ]]; then
  echo "Run commands for Android builds here"
elif [[ "$EAS_BUILD_PLATFORM" == "ios" ]]; then
  echo "Run commands for iOS builds here"
fi

package.json and Node script

package.json
{
  "name": "my-app",
  "scripts": {
    "eas-build-pre-install": "node pre-install.js",
    "start": "expo start"
    // ...
  },
  "dependencies": {
    // ...
  }
}
pre-install.js
// This is a file called "pre-install.js" in the root of the project

if (process.env.EAS_BUILD_PLATFORM === 'android') {
  console.log('Run commands for Android builds here');
} else if (process.env.EAS_BUILD_PLATFORM === 'ios') {
  console.log('Run commands for iOS builds here');
}
  • Message-iconAsk a question on the forums
  • Edit-iconEdit this page

Was this doc helpful?