Search code examples
react-nativeexpo

Expo environment variables for updates not being picked up


Currently strunggling to understand how to correctly define ENV var based on context.

Here is my example eas.json

    {
      "build": {
        "development": {
          "developmentClient": true,
          "distribution": "internal",
          "channel": "development",
          "env": {
            "EXPO_PUBLIC_API_URL": "http://localhost:3000"
          }
        },
        "preview": {
          "distribution": "internal",
          "channel": "staging",
          "env": {
            "EXPO_PUBLIC_API_URL": "https://staging.domain"
          }
        },
        "production": {
          "channel": "main",
          "env": {
            "EXPO_PUBLIC_API_URL": "https://prod.domain"
          }
        }
      }
    }

I also have an .env.local, referencing it (as i assume, eas.json wont get picked on laptop dev):

    #DO NOT COMMIT THIS
    SENTRY_AUTH_TOKEN=xxxx
    EXPO_PUBLIC_API_URL=http://localhost:3000

When running update

eas update --branch staging --message "feat(onboarding): navigation"

No matter what, env.local takes over. What should be fixed to have it correctly working ? I want eas.json preview.env.EXPO_PUBLIC_API_URL to be picked up


Solution

  • Simply change you ENV variables value in your .env.local file from

    http://localhost:3000

    to

    https://staging.domain

    Your flow and eas.json file is correct but is purely for building. For example, when you want a preview build, it will use those predefined ENV variables. But to test locally, you will need to change your .env.local file.

    Be sure to restart your development server!

    Edit:

    These predefined env variables are for building

    eas build --profile [development | preview | production] --platform [android | ios]