Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EAS ENV VARIABLES NOT PICKED UP DESPITE FOLLOWING DOCUMENTATIONS #2729

Open
Zakisb opened this issue Nov 27, 2024 · 1 comment
Open

EAS ENV VARIABLES NOT PICKED UP DESPITE FOLLOWING DOCUMENTATIONS #2729

Zakisb opened this issue Nov 27, 2024 · 1 comment

Comments

@Zakisb
Copy link

Zakisb commented Nov 27, 2024

Build/Submit details page URL

https://expo.dev/accounts/zakisb97/projects/gogain/builds/16e1e538-4314-420d-9bd1-996f3e773739

Summary

Environment variables are not being properly injected into EAS builds despite following multiple documented approaches:

Set env variables in eas.json build profiles
Defined variables in EAS Dashboard under the correct profile
Hardcoded values directly in eas.json for testing
Triggering EAS builds from Azure CI pipeline

As a trick to confirm i hae the right env variables. i had a screen with touchable opacity when i click it alerts the EXPO_PUBLIC_API_URL . THE PROBLEM IT SHOWS EMPTY STRING AND Every screen that needs an api call isn't working.

Important Note: The builds are triggered remotely on EAS servers via Azure pipeline, NOT built locally within Azure. The Azure pipeline simply initiates the EAS build process.

Expected: Environment variables (EXPO_PUBLIC_API_URL, EXPO_PUBLIC_APP_NAME) should be accessible in the app for different environments (preview/production).

Actual: Only Clerk secret keys are being successfully injected. All other environment variables are undefined in the built app.

Attempted Solutions:

Using variable references in eas.json:

  "build": {
    "preview": {
      "autoIncrement": true,
      "env": {
        "APP_ENV": "staging",
        "EXPO_PUBLIC_API_URL": "EXPO_PUBLIC_API_URL",
        "EXPO_PUBLIC_APP_NAME": "EXPO_PUBLIC_APP_NAME"
      },
      "distribution": "store",
      "environment": "preview",
      "channel": "preview"
    },
    "production": {
      // Similar configuration...
    }
  }
}

Hardcoding values directly in eas.json:

{
  "build": {
    "preview": {
      "autoIncrement": true,
      "env": {
        "APP_ENV": "staging",
        "EXPO_PUBLIC_API_URL": "https://api-staging.myapp.pro",
        "EXPO_PUBLIC_APP_NAME": "My App (Preview)"
      },
      "distribution": "store",
      "environment": "preview",
      "channel": "preview"
    },
    "production": {
      // Similar configuration...
    }
  }
}

Additional Context:

1.env files are not pushed to branches
2. Two separate branches (preview/prod) with different API endpoints
3. Following EAS documentation stating .env files are optional
4.Using eas.json for build configuration
5.Builds are triggered on EAS servers via Azure pipeline, not built locally in Azure
6Environment specific variables need to be available on the app.

Managed or bare?

bare

Environment

expo-env-info 1.2.1 environment info:
System:
OS: macOS 14.0
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
Yarn: 1.22.22 - /opt/homebrew/bin/yarn
npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
Watchman: 2024.11.18.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.15.2 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 23.5, iOS 17.5, macOS 14.5, tvOS 17.5, visionOS 1.2, watchOS 10.5
IDEs:
Xcode: 15.4/15F31d - /usr/bin/xcodebuild
npmPackages:
babel-preset-expo: ^11.0.13 => 11.0.15
expo: ^51.0.18 => 51.0.39
expo-router: ~3.5.20 => 3.5.24
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.74.5 => 0.74.5
react-native-web: ~0.19.10 => 0.19.13
npmGlobalPackages:
eas-cli: 12.5.1
Expo Workflow: bare

Error output

Errors happens on pages requiring api call.

Reproducible demo or steps to reproduce from a blank project

Simple demo project . add eas.json variables like shown in summary and ignore .env files via gitignore. that's it.

@Zakisb Zakisb added the needs review Issue is ready to be reviewed by a maintainer label Nov 27, 2024
@szdziedzic
Copy link
Member

Hey,

If you look into your Spin up build environment phase logs you can see that both EXPO_PUBLIC_API_URL and EXPO_PUBLIC_APP_NAME are present there. How do you access these variables in your app?

Can you also upgrade EAS CLI to the latest version? You seem to have eas-cli: 12.5.1 installed (at least locally).

@szdziedzic szdziedzic added eas build and removed needs review Issue is ready to be reviewed by a maintainer labels Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants