-
Notifications
You must be signed in to change notification settings - Fork 84
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
Using environment variables in app.config.ts
doesn't work with eas update
#2222
Comments
I just encountered the same issue. Thanks for the workaround for now! |
did you create the prebuild? i encoutered same issue, i solved by prebuild creation instead of set NODE_ENV. |
I don't think prebuild is relevant here, since prebuild is an |
I was facing a similar issue, so hope I can share some insights. I am using an expo app with different app variants [staging, production]. This is my eas config "staging": {
"distribution": "store",
"env": {
"APP_VARIANT": "staging"
},
"channel": "staging",
"autoIncrement": true
},
"production": {
"channel": "production",
"autoIncrement": true
} And my app.config.ts is something like this export default ({ config }: ConfigContext): ExpoConfig => {
const isStaging = process.env.APP_VARIANT === 'staging';
const productionConfig: ExpoConfig = {
...config,
name: 'App',
ios: {
bundleIdentifier: 'com.xxxx.influencer',
},
android: {
package: 'com.xxxx.influencer',
},
extra: {
eas: {
projectId: '8c24d46b-xxxx-45f1-xxxx-xxx571c7xxxx',
},
GQL_URL: 'https://gql.xxxx.com/graphql/',
},
updates: {
url: 'https://u.expo.dev/xxx-xxxx-45f1-9379-dce571cxxx',
},
runtimeVersion: {
policy: 'appVersion',
},
};
if (isStaging) {
return {
...productionConfig,
name: '(Stg)App',
ios: {
...productionConfig.ios,
bundleIdentifier: 'com.xxxx.influencer.staging',
},
android: {
...productionConfig.android,
package: 'com.xxxx.influencer.staging',
},
extra: {
...productionConfig.extra,
GQL_URL: 'https://stg-gql.xxxx.com/graphql/',
},
};
}
return productionConfig;
}; For building the app (for staging) I use these commands
Till this point, everything works fine. The build can properly set all environment variables, as I have specified the profile with Also, on the app.config.ts, it can pick up the correct env[staging]. The problem happens with the eas update!I was trying to push an update on my staging variant with the following command
Although I was sending the update to the staging branch, the new update wasn't able to pick the Probably, it was undefined on Finally, I was able to fix that by setting the
On the CI, it will be something like this
|
I am having an issue with the build not the eas update, I am trying to set a new projectId based on configurations but it keeps failing when running the eas build worker, i thought you might have an input here |
Thanks for your workaround @andrejpavlovic - however I found an issue which is preventing me from continuing, I load the dotenv config using the ES6 method: And for some reason the config is being called 3 times, once with the correct process.env var set and twice more with it undefined: // app.config.ts
export default ({ config }: ConfigContext): ExpoConfig => {
const url = `https://u.expo.dev/${process.env.EXPO_PROJECT_ID}`;
console.log('URL', url);
...
}; // output
[[email protected]][INFO] Loading env from encrypted .env.vault
URL https://u.expo.dev/022xxxxx-eb2e-xxx-b078-24xxxxxfb2d
URL https://u.expo.dev/undefined
URL https://u.expo.dev/undefined
It looks like you are using a dynamic configuration! Learn more: https://docs.expo.dev/workflow/configuration/#dynamic-configuration-with-appconfigjs)
Add the following EAS Update key-values to the project app.config.js:
Learn more: https://expo.fyi/eas-update-config EAS is only being called once with this command: Interestingly, when using your method of
It would be nice for this to work as expected by EAS. |
I have solved this issue for me anyway by utilising This was discovered as Summary:
If you need additional env vars passed in then set them before dotenvx:
Hope this helps someone until Expo/EAS fix this as it is a bit annoying and 🤯 |
Using dotenv cli to load the env variables is the only viable solution to this problem. The documentation is really confusing on this topic, especially since "update" is an EAS command, you'd expect it to use variables from eas.json at least, but no - it doesn't load variables from neither eas.json nor env files. See #1265 (comment) Here's how I've done it (with dotenv-cli as a project dependency):
|
@AdamGerthel if you use npx then you don't need to install it as a project dependency, it will download it and use it on demand. |
The above approach solved my issue. the last call was not persisting env variables. Thank you so much for this workaround😊 |
@ChromeQ Thanks!!!! That helped me after a lot of frustration! |
This is the easiest and cleanest solution for me. Thank you so much! |
I encountered the same issue. Using a TypeScript app.config file and an env file named |
Build/Submit details page URL
No response
Summary
How do I get
eas update
to properly loadapp.config.js
file that references environment variables, if those aren't available wheneas update
is executed?Let's say I have an
.env
file with this environment variable:I use this value in
app.config.js
for something and ensure it is not empty:✔️ Running expo command such as
yarn expo config
works fine, since the environment variable is automatically loaded from.env
file.❌ However when running
eas config
oreas update
, the error above is thrown becauseMY_VALUE
environment value is not available.Now, I understand that eas is not supposed to be reading
.env
values, but the issue here is that it's reading the expo config which uses environment variables.So I thought adding
MY_VALUE
toeas.json
asenv
value would fix the issue, but it only works foreas config
.eas update
doesn't read environment values even fromeas.json
.If
eas update
doesn't read environment values from.env
or fromeas.json
then why is it loadingapp.config.js
which more than likely relies on environment values in order to configure expo plugins, etc.?My workaround for now was to just load
.env
manually inapp.config.js
:Managed or bare?
managed
Environment
expo-env-info 1.2.0 environment info:
System:
OS: Windows 10 10.0.19045
Binaries:
Node: 18.18.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 10.2.5 - C:\Program Files\nodejs\npm.CMD
Watchman: 20210110.135312.0 - C:\ProgramData\chocolatey\bin\watchman.EXE
IDEs:
Android Studio: AI-231.9392.1.2311.11330709
npmPackages:
expo: ~50.0.6 => 50.0.6
react: 18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0
react-native: 0.73.4 => 0.73.4
react-native-web: ~0.19.10 => 0.19.10
Expo Workflow: bare
✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check npm/ yarn versions
✔ Check for issues with metro config
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check that packages match versions required by installed Expo SDK
✔ Check that native modules do not use incompatible support packages
✔ Check for legacy global CLI installed locally
✔ Check that native modules use compatible support package versions for installed Expo SDK
Error output
No response
Reproducible demo or steps to reproduce from a blank project
Description posted above.
The text was updated successfully, but these errors were encountered: