EAS Build New Style eas.json Environment Variables Not Working

Hello,

I have been successfully using EAS build for many weeks now. I recently had to perform the automated migration of eas.json to the new format using the cli. Ever since I have done this, my application does not seem to be receiving the environment variables it was previously. I used to be able to access environment variables set using the env key in eas.json from process.env but they now all appear to be undefined. It is a little difficult to debug this problem since I need to run a build each time so I can’t rule out another cause but I would be grateful if you could just confirm that there isn’t something wrong with my new eas.json.

Example from original eas.json:

{
  "builds": {
    "android": {
      "development-sandbox": {
        "workflow": "managed",
        "distribution": "internal",
        "releaseChannel": "development-sandbox",
        "env": {
          "API_URL": "xxxx",
          "XXX": "xxx",
          "XXX": "XXX",
          "XXX": "XXX"
        }
      }
    },
    "ios": {
      "staging-testflight": {
        "workflow": "managed",
        "distribution": "store",
        "releaseChannel": "staging",
        "env": {
          "API_URL": "xxxx",
          "XXX": "xxx",
          "XXX": "XXX",
          "XXX": "XXX",
          "IOS_BUNDLE_ID": "x.x.x",
          "APP_NAME": "XXX (Staging Live)",
          "APP_ICON": "./assets/icon_staging.png"
        }
      },
      "staging-sandbox-testflight": {
        "workflow": "managed",
        "distribution": "store",
        "releaseChannel": "staging-sandbox",
        "env": {
          "API_URL": "xxxx",
          "XXX": "xxx",
          "XXX": "XXX",
          "XXX": "XXX",
          "IOS_BUNDLE_ID": "x.x.x",
          "APP_NAME": "XXX (Staging Sandbox)",
          "APP_ICON": "./assets/icon_sandbox.png"
        }
      },
      "development-sandbox": {
        "workflow": "managed",
        "distribution": "internal",
        "releaseChannel": "development-sandbox",
        "env": {
          "API_URL": "xxxx",
          "XXX": "xxx",
          "XXX": "XXX",
          "XXX": "XXX",
        }
      }
    }
  }
}

Migrated eas.json

{
  "build": {
    "development-sandbox": {
      "android": {
        "env": {
          "API_URL": "xxxx",
          "XXX": "xxx",
          "XXX": "XXX",
          "XXX": "XXX",
        }
      },
      "ios": {
        "env": {
          "API_URL": "xxxx",
          "XXX": "xxx",
          "XXX": "XXX",
          "XXX": "XXX",
        }
      },
      "releaseChannel": "development-sandbox",
      "distribution": "internal"
    },
    "staging-testflight": {
      "ios": {
        "releaseChannel": "staging",
        "env": {
          "API_URL": "xxxx",
          "XXX": "xxx",
          "XXX": "XXX",
          "XXX": "XXX",
          "IOS_BUNDLE_ID": "x.x.x",
          "APP_NAME": "XXX (Staging Live)",
          "APP_ICON": "./assets/icon_staging.png"
        },
        "distribution": "store"
      }
    },
    "staging-sandbox-testflight": {
      "ios": {
        "releaseChannel": "staging-sandbox",
        "env": {
          "API_URL": "xxxx",
          "XXX": "xxx",
          "XXX": "XXX",
          "XXX": "XXX",
          "IOS_BUNDLE_ID": "x.x.x",
          "APP_NAME": "XXX (Staging Sandbox)",
          "APP_ICON": "./assets/icon_sandbox.png"
        },
        "distribution": "store"
      },
    }
  }
}

run eas config to debug what env vars will be provided. also look at the ‘Build environment info’ step in on the build details page to see what env vars are set on the build

1 Like

Thank you,

I have been looking into this further and the Build environment info has helped me to confirm that the correct environment variables are being passed in.

I discovered during this process a detail I had never really thought about; that, as I understand, EAS replaces process.env.X with the value of the environment variable during the build process. I wondered if there was an easy way of seeing the code after this transformation has been applied to check if my code is working correctly.

Thank you for your help

eas does not inline env vars in your code, you need to set that up in your project (like with all react native apps), eg: babel-plugin-transform-inline-environment-variables · Babel

So that means that the environment variables are not available in process.env at runtime?

I’ll take that as a no

process.env refers to the env on your computer. you are running code on your phone. if you want to make the env vars available on your phone, then you need to inline the vars (replace process.env.X with ‘value-of-x’). it’s explained in the doc