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 Build not passing environment variables from eas.json to expo prebuild step #2812

Open
jai-sohu opened this issue Jan 11, 2025 · 0 comments
Labels
needs review Issue is ready to be reviewed by a maintainer

Comments

@jai-sohu
Copy link

Build/Submit details page URL

https://expo.dev/accounts/umanapp2022/projects/app-owner/builds/b1e31cd5-a8a2-4fcb-8377-933ca0b8369f

Summary

I have the following eas.json configuration
{
"cli": {
"version": ">= 5.9.1",
"appVersionSource": "local"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"channel": "development",
"env": {
"APP_ENV": "development"
}
},
"development-simulator": {
"developmentClient": true,
"distribution": "internal",
"ios": {
"simulator": true
},
"env": {
"APP_ENV": "development"
}
},
"preview": {
"distribution": "internal",
"channel": "preview",
"env": {
"APP_ENV": "production"
}
},
"production": {
"channel": "production",
"env": {
"APP_ENV": "production"
}
}
}
}

And my app.cofig.ts file is as follows
/* eslint-disable sort-keys-fix/sort-keys-fix */

import { config } from "dotenv";
import fs from "fs";
import path from "path";

const getEnvironmentFile = (env) => {
switch (env) {
case "production":
return ".env.production";
case "development":
return ".env.development";
default:
throw new Error(Unknown environment: ${env});
}
};

const env = process.env.APP_ENV || "development";
const envFile = path.resolve(__dirname, getEnvironmentFile(env));

if (fs.existsSync(envFile)) {
config({ path: envFile });
} else {
throw new Error(Environment file ${envFile} does not exist);
}

export default () => {
return {
expo: {
name: "Test",
slug: "app-owner",
owner: "abc",
version: process.env.APP_VERSION,
orientation: "portrait",
icon: "./assets/icon.png",
userInterfaceStyle: "light",
splash: {
image: "./assets/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff",
},
assetBundlePatterns: ["**/*"],
ios: {
supportsTablet: true,
bundleIdentifier: "com.abc.com",
config: {
usesNonExemptEncryption: false,
},
buildNumber: process.env.IOS_BUILD_NUMBER,
},
android: {
softwareKeyboardLayoutMode: "pan",
googleServicesFile: process.env.GOOGLE_SERVICES_JSON,
adaptiveIcon: {
foregroundImage: "./assets/adaptive-icon.png",
backgroundColor: "#ffffff",
},
package: "com.abc.com",
versionCode: parseInt(process.env.ANDROID_VERSION_CODE, 10),
},
web: {
favicon: "./assets/favicon.png",
bundler: "metro",
},
plugins: [
"expo-localization",
"expo-updates",
[
"expo-build-properties",
{
ios: {
flipper: false,
deploymentTarget: "13.4",
},
},
],
"expo-font",
],
runtimeVersion: {
policy: "appVersion",
},
},
};
};

When i run eas build with production profile, then i have seen logs in the expo.dev ui
The step "Read app config" is correctly reading the passed environment variables from eas.json and hence the app versions are getting picked correctly.
But in the "Prebuild" step the environment variables are not getting picked correctly, in that case APP_ENV becoming undefined and hence by my logic in app.config.js, .env.development file is getting picked, thus it is leading to wrong app versions setting in android/ios native directory

Managed or bare?

Managed

Environment

expo-env-info 1.2.2 environment info:
System:
OS: macOS 15.2
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.20.4 - ~/.nvm/versions/node/v18.20.4/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.4/bin/yarn
npm: 10.7.0 - ~/.nvm/versions/node/v18.20.4/bin/npm
Watchman: 2024.11.11.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.15.2 - /Users/jai.sohu/.gem/ruby/2.7.4/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 24.1, iOS 18.1, macOS 15.1, tvOS 18.1, visionOS 2.1, watchOS 11.1
Android SDK:
API Levels: 33, 34
Build Tools: 33.0.1, 34.0.0
System Images: android-34 | Google Play ARM 64 v8a
IDEs:
Android Studio: 2024.1 AI-241.19072.14.2412.12360217
Xcode: 16.1/16B40 - /usr/bin/xcodebuild
npmPackages:
babel-preset-expo: 11.0.15 => 11.0.15
expo: 51.0.26 => 51.0.26
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.74.2 => 0.74.2
react-native-web: 0.19.12 => 0.19.12
npmGlobalPackages:
eas-cli: 14.4.0
Expo Workflow: managed

Error output

Prebuild

yarn run v1.22.21
$ /home/expo/workingdir/build/node_modules/.bin/expo prebuild --no-install --platform android
env: load .env.development
env: export APP_VERSION ANDROID_VERSION_CODE IOS_BUILD_NUMBER API_URL

  • Creating native directory (./android)
    ✔ Created native directory
  • Updating package.json

Reproducible demo or steps to reproduce from a blank project

Simply create a project and follow the steps that i have mentioned in the problem description itself and you will be able to reproduce it

@jai-sohu jai-sohu added the needs review Issue is ready to be reviewed by a maintainer label Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Issue is ready to be reviewed by a maintainer
Projects
None yet
Development

No branches or pull requests

1 participant