-
Notifications
You must be signed in to change notification settings - Fork 85
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 is a major issue and there's still no answer for it. I'm currently on the "on-demand" plan in EXPO Dev, which means I pay $1 every time I do a build, and before I realised that this was an issue with EXPO, and not my code, I did at least 5 builds + the time and effort wasted on trying to find an issue that is not even in my application. We need this fixed ASAP!!! |
I am also experiencing this issue. When values are defined in my .env file as EXPO_PUBLIC_VAR, and in my eas.json, when running locally none of the variables appear. |
For me, the script below successfully makes the environment variables available for eas build, since it directly sources the .env file in the current shell context. This is more reliable and ensures that all environment variables are properly loaded and available for the eas build command set-env.sh:
run it like this: |
You. Are. A. Godsend. I can confirm this actually worked. Just a small correction to this:
You do not need to rename your app.json to app.config.js, I'm sure they both work the same, but you can keep your existing app.json and add on Thank youuuuuu!!!! |
Same issue for me and it took me a while to figure it out. iOS doesn't say anything, and crash report is useless. Thanks guys ! |
I still don't understand what's at play here. This is basically eas-cli's whole job, and it USED to work. Latest versions 11.x break environment variable resolution. |
In addition to npm i dotenv-cli -D For "build:android": "dotenv -c development -- eas build --platform android --profile preview --local", Package docs: https://www.npmjs.com/package/dotenv-cli |
I waste time and money with this issue, please fix it ASAP! Im willing to help if you need it @Expoteam |
Did you guys try to change to
in babel.config.js ? |
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",
}
} |
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: