-
Notifications
You must be signed in to change notification settings - Fork 88
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
Environment variables don't seem to be detected in build #2195
Comments
Apparently Expo only supports dot notation for accessing env variables. Which is strange because it worked with Expo Go. I'll try changing the validator to use dot notation and report back. |
Update: After changing my validator to use dot notation, I'm still getting the same error about missing env vars |
Hi there, I wanted to check your build logs, but they are expired. Are you still facing this issue? If so may I ask you to run the build once again and send me the link? |
@szdziedzic I'm not working on this project anymore as my client decided to pivot, but I'll try to re run the build when I have some free time |
Can confirm this a real issue I am facing. |
I am having the same issue as well |
Hello was this solved. I have the same issue. It works fine in expo go but when I run a dev build they are all undefined. |
Has anyone found a solution to this issue yet ? |
I had a similar issue, while doing local eas build. Everything looks to be working well with expo builds, but fails during eas local builds. It appears that I needed to set the environment variables for the execution of build command. So, here is what I did -
|
this is still an issue, the above script by @anup-a doesn't work for me. have a .env file and also a eas.json file
still not working. kind of a big deal breaker and show stopper for running local builds where you can't leverage EAS cloud builds due to enterprise compliance reasons? trying to call this in app code
i get 'did not load' in the development and production apk builds of the app ONLY, in expo go and the web browser it loads. any advice? |
I have the same issue here |
Yeah this is really problematic for me also, on production builds the env vars just are not present. |
Similar-ish issue here. |
Facing a similar issue |
In the end this was me missing a vital piece of documentation on the standard env resolution I had a Weird gotcha, but I resolved this by combining the CI and app envs into a single |
I am facing the same issue, although the env variable is detected in dev mode, it is not when I run eas build, even though the logs show that it is loaded |
You need to add EXPO_PUBLIC_ befor each variable |
This is annoying. |
I even manually exported them, still facing the issue, no env vars were being read |
Having the same issue here, I can see the variable in the eas spin-up build environment too but its not there in the app. |
I'm having the exact same issue! I can't make the production build app work because the ENV are not present anymore. It all started after updating from Expo 49 to 50!!! This is ridiculous! |
Well, that's weird. If I have |
@samimenouar , That's very strange! Have you built the apk and the env variables work after you console.log the process.env? |
I managed to find a solution. (Was pretty scared to see an opened issue from January) I added my env in eas.json, ex:
I wrote in app.config.js (if you don't have it it's app.json and you have to rename it):
Then i have a file named model.tsx and i used the expo-constants library (yarn add expo-constants, or npm install):
Now everywhere i import import { API_URL } from "./model"; it has the right value. |
Can confirm the above works as well. Similar solution referenced in the Expo discord here |
This fix works for me but there might be a better way to fix it. Basically what I have observed is that when the .env file is gitignored then environment variables are not loaded. So before generating the build we need to remove it from the .gitignore file.
I only have .env file and didn't add env property in the eas.json |
Thats an interest solution, do you think that is the same for local build (with --local flag)?? |
I haven't tried building locally yet but if you are facing the issue because the environment variables are not loaded properly, you can try this way. |
Works for me in combination with: #2195 (comment) solution |
Solution for Using Environment Variables in Expo with EAS BuildAfter diving deep into Expo's documentation and blogs, I’ve finally figured out how to properly handle environment variables in Expo projects, especially with EAS builds. I’m sharing this to help others who might run into the same issues. First, I recommend reviewing the following: How it Works
Step-by-Step Guide
Important Note:
Using Environment Variables in EAS BuildsIf you want to use your local environment variables during EAS builds:
This tells EAS to look for Pushing Secrets Directly from the Command LineTo avoid manually setting up secrets in the Expo dashboard, you can push your eas secret:push --scope project --env-file .env This will automatically upload your existing env to project specific secrets. I hope this helps someone else in the future because dealing with this was a total nightmare! But now that I understand the flow of Expo’s configurations, it’s much clearer! PS: If you have anything to add, or if you think I might’ve misunderstood something, I’m all ears. A Few Key Notes:
|
It looks like the use of EXPO_PUBLIC* env vars has some drawbacks. The docs do discuss how to centralize configuration variables based on channels (and prevent EAS Updates from overriding the vars set by EAS Build which is what I believe is happening to most people here, me included). |
This did work for me, I can now access env variables in both development an eas builds. |
This your solution works for me |
Solution from @Ception works for me. |
this works and it's clearer than the docs. thank you! |
This is still going on 😁 |
I saw this repost in a million other github forums and in redit but it doesnt work for me. I have my env (in local ) that is EXPO_PUBLIC_API_URL, and in expo screts i have EXPO_PUBLIC_API_URL_DEVELOPMENT and EXPO_PUBLIC_API_URL_PRODUCTION. when i access it with process.env.EXPO_PUBLIC_API_URL_DEVELOPMENT i dont have any problems (the build is using the expo secrets) buttt, when i try to use it in the eas.json like this
it use the literal string "EXPO_PUBLIC_API_URL_DEVELOPMENT" or "EXPO_PUBLIC_API_URL_PRODUCTION". im trying to use it in the eas for convenience but i will try the app.config.js option |
Hi, sorry for the late response. Here is my build log: https://expo.dev/accounts/jorensm/projects/app/builds/58dc3481-75ce-43b1-bffd-5c4b46499a62 (hopefully you can access it with this link) And my
|
Although this may work, I'm not sure if that's the expected behavior. I think that Secrets and Env Vars are different and have different uses. From one of the pages you linked:
|
The "EAS secrets" doc page is unreachable it's pretty annoying :'( |
iNSANE NO ONE FROM THE EXPO AND EAS TEAM JOINED THE DISCUSSION AND PROVIDED A FIX ! WHAT ARE THEY DOING ? |
In my case, I tried many approaches and built a scenario for every possibility to access variables in my code (plain text, secret, declared directly in eas.json, added on the Expo website, with and without the EXPO_PUBLIC_ prefix). What ultimately worked for me was the following setup:
Configure the environment in the Expo dashboard for each build type (e.g., preview and production in my case) and ensure the build process is properly declared in eas.json
) I had multiple variables with identical names on the Expo dashboard, all prefixed with EXPO_PUBLIC_. The difference between them was the build environment they were associated with (e.g., preview or production). These prefixes were necessary because the variables needed to be available directly in my code, removing them didn't work. I accessed these variables in my code using process.env. However, attempting to retrieve them elsewhere with a dynamic approach, such as:
did not work for me (took me a long time to figure it out, dynamic call after build doesn't seem to work). I've got non prefixed variables but they are only for build purpose. process.env reach them during build. Hope this will help someone ! Have a nice day |
Setting up Supabase with Expo Updates and EASIf you're struggling with Supabase integration, here's what worked for me: Understanding the IssueEnvironment variables are being picked up during the build phase but not during updates, as updates don't get access to env vars from Expo directly. My Setup
Key Solution: Using Environment FlagThe crucial part is using Step-by-Step Implementation
Now, when your app is built / an update is published, the env variable will be available for the app! 🎉 For GitHub Actions UsersIf using continuous-deploy-fingerprint:
|
can't believe this issue has been open for over two years and still has no support from expo team. 😠 |
I'll try to bring some clarity from my experience. dev buildsEXPO_PUBLIC_XXX is meant to be used with .env files. so, you may use it on local build like this : `.env.local EXPO_PUBLIC_ICON_PREFIX=icon_dev Then when running this allows your local build to access vars like this EAS builds
So, you have to use EAS env vars. When setting your eas.json, you can use EXPO_PUBLIC_XXX, but don't have to. Here is what I do : "build": {
"production": {
"env": {
"ICON_PREFIX": "icon_prod",
"MY_SECRET": "will_be_overwritten"
}
}
} const appConfig: AppConfig = {
iconPrefix: process.env.EXPO_PUBLIC_ICON_PREFIX as string,
mySecret: process.env.EXPO_PUBLIC_MY_SECRET as string,
}
if (process.env.APP_VARIANT !== "development") {
Object.assign(appConfig, {
iconPrefix: process.env.ICON_PREFIX,
mySecret: process.env.MY_SECRET,
})
}
return {
ios: {
icon: `./src/images/${appConfig.iconPrefix}_ios.png`,
},
extra: {
mySecret: appConfig.mySecret
}
} this allows your cloud build to access vars like this : import Constants from "expo-constants"
[...]
Constants.expoConfig?.extra?.mySecret Hope it will help. PS : "build":
"development": {
"developmentClient": true,
"distribution": "internal",
"env": {
"EXPO_PUBLIC_ICON_PREFIX": "icon_dev",
"EXPO_PUBLIC_MY_SECRET": "will_be_overwritten",
}
} |
It's just silly and eas is still a paid service. No after sales service or instructions? |
It's crazy!!. Like we know that these variables will be accessible in the bundles anyways so why make it so difficult. Just detect the .env file and let people upload their .env files to eas and autofill it in the server build 🤦♂️. I can't count how many things I've had to hoist to a server because env variable management is still so shotty in expo |
Hi, I've just been through this process and I think I've found a solution on how we should manage environment variables with eas. In my case I use plain text and secret variables (and files). I use secret keys for files and for tokens for authorization via Facebook, Google and Apple. Due to the fact that I have two test and production environments, I have the same variables declared in eas for different environments - eas recognizes them and substitutes the appropriate variable values for a given build. Not only do I use variables, I also have files like GOOGLE_SERVICES_JSON and GOOGLE_SERVICE_INFO_PLIST which I also store in eas and use when building the application in every mode (dev, preview, prod). This is what it looks like in eas: In developer mode, I use emulators and physical devices - it works fine for everyone. Below are instructions on how I have it configured and how to make everything work with EAS for both the development and production environments:
As you can see, in this configuration the paths to googleServicesFile and apiKey are given, taken from process.env. I also have local files google-services.json and GoogleService-Info.plist which are in .gitignore. For the test environment the application uses local files, for preview and production environments, eas already acquires keys added in expo.dev. Further in the configuration I have the following variables declared in expo.extra[...]: It is thanks to this declaration that your development or production environment has access to these variables (development from the .env.local file, and production from eas. Now let's move on to the eas.json file, because it is the most important for the environments we are building: Notice that in this place for each environment variables are declared which eas is to use during application building (per environment). Very important! - you do not provide here all variables declared as EXPO_PUBLIC_[...]. Eas will load them itself because they are public. The only place where you declare them is in expo.extra (app.config.js). have declared variables per environment in expo.dev with the same name, e.g.: EXPO_PUBLIC_API_ENDPOINT (development = https://mytestenv.com) Eas will recognize whether it should take the value for the test environment or the production environment:
This is where the application uses variables declared in the app.config.js file (expo.extra[..]). At the very end: Check during the application building process (e.g. for a production environment) whether all variables have loaded correctly (section - Spin up build environment): Remember! that if you change something in the .env.local file, you need to restart expo in development mode - npx expo start -c (-c removes the cache). If you change something on the expo.dev side in variables, you need to rebuild the application, e.g. (eas build --platform ios --profile development). Done! the application works in development mode, development mode for emulator, preview and production. |
Same issue, found with both remote builds and |
Having an issue, @expo your docs are absolute 💩 you need to be more clear, and consider cases such as local builds here. I understand you're incentivizing clouds builds so you can charge 💸 , but you're losing customers by delivering a broken product. |
Sorry guys, if there is a way to configure the environment variables very easily on the expo servers: https://expo.dev/accounts/%5Baccount%5D/projects/%5Bproject%5D/environment-variables |
Hi @expo, can you please take a look at this issue? This is affecting us as well and we are paying customers. |
To whomever it helps, I've been banging my head at a wall with this for the past week. I was able to see the vars listed in I added Hope it helps! edit: more info on eas hooks here. |
Build/Submit details page URL
https://expo.dev/accounts/jorensm/projects/app/builds/3dcb9d5c-dfb2-487d-a6e5-8ce5c65b2288
Summary
So I'm trying to add environment variables to my EAS build. I've added them in my
eas.json
file, like so:But they don't seem to be detected in my build. I have a validator function that throws an error if the env variables are not set, and its throwing it in my builds, thought it works fine with Expo Go.
Managed or bare?
Managed
Environment
expo-env-info 1.2.0 environment info:
System:
OS: Windows 10 10.0.19045
Binaries:
Node: 20.8.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
SDKs:
Android SDK:
API Levels: 30, 31, 33
Build Tools: 30.0.2, 30.0.3
IDEs:
Android Studio: Version 2020.3.0.0 AI-203.7717.56.2031.7678000
npmPackages:
@expo/webpack-config: ^19.0.0 => 19.0.0
expo: ~49.0.15 => 49.0.21
expo-router: ^2.0.0 => 2.0.14
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.72.6 => 0.72.6
react-native-web: ~0.19.6 => 0.19.10
Expo Workflow: managed
expo-doctor
didn't find any issuesError output
No response
Reproducible demo or steps to reproduce from a blank project
This is the file that loads my env variables. On Expo Go it doesn't throw an error but on a EAS build it does.
The text was updated successfully, but these errors were encountered: