EAS Build - Custom Development Client - Environment Variables No Longer Work After Initial Build

Hello! I am not sure if this is an EAS issue per-say or a expo-dev-client issue. I am experiencing some weird behaviors while using the environment variables in the eas.json file with the custom development clients. Our application currently uses:

  • Expo SDK 42
  • expo-dev-client 0.6.3
  • eas-cli 0.34.1
  • babel-plugin-transform-inline-environment-variables 0.4.3

We currently have ‘development’ and ‘staging’ profiles setup in our eas.json file with all of the appropriate environment variables per each profile. In pushing up our staging configuration to TestFlight , everything works as expected; the environment variables have the expected values. However, if we use the ‘development’ profile as an internal distribution build (using eas build), install the resulting .apk on our own devices, and use ‘expo start --dev-client’ locally, the environment variables no longer work as expected.

For some reason, only the very first build under our ‘development’ profile (with distribution set to ‘internal’ and developmentClient set to true) worked with environment variables. Since that initial build, any file change to the native application results in the removal of all environment variables from process.env. It does not matter what code or file change occurs, the result is the same: process.env loses all of the environment variables.

We have rebuilt the .apks by re-running eas build, cleared the expo cache, cleared our device caches, nothing seems to work for running locally via the custom development client. Nothing seems to work other than reverting the codebase back to what it was during the initial build.

This is one of the last pieces in getting our application fully up and running with EAS, and any help would be greatly appreciated.

hi brandon!

the environment variables are used only at build time, while building the app binary. if you would like to also load those in your development js code, you should set them within the environment on your machine.

I do see that it is building the internal dev client APK with the correct variables. Why does it work locally when using the same code base as the initial build? If we run ‘expo start --dev-client’ with our original codebase of the first build, the environment variables seem to work as expected.

i can’t really say what would be happening there without an example. but when you run expo start --dev-client locally, none of the environment variables set in eas.json are used.

Ah okay. I always thought the environment variables would have been baked into the custom development client APK when that gets built (the build logs show its configuring the build environment with the set env variables). Is that not the case?

it… depends. if the environment variables are responsible for setting values in app.config.js, and those values in app.config.js control the behavior of your app at build time (eg: name, bundle id, etc) then yes it will get “baked in” in the sense that it will be evaluated at build time and then that config value will be used. but if you just try to access the environment variable from App.js or other app code, then it will not.

We are currently using them for the later so that makes sense. For our staging builds (like those being submitted to TestFlight), those seem to be working as expected (referencing the variables in actual code using process.env). Is it different? Or is them working some kind of fluke.

if you use babel-plugin-transform-inline-environment-variables and you are not building a dev client then the env variables set on eas build will also be used when building your js app. the thing is that when you build a dev client, we don’t build the js code from App.js - that is left to your local machine when you run expo start --dev-client

also note that when you run expo start --dev-client we will again evaluate app.config.js locally everytime you load the app in the dev client, and that’ll be used to configure the app in ways that can be done at runtime (most can only be done at build time)

Got it. I’m using app.json but I’m guessing its the same concept. So ideally to get these env variables working locally with the dev client, just set them in my system environment variables (using a windows machine), and then they’ll be available in process.env?

–EDIT: That did it! I just want to say, thank you so much for your help :slight_smile: :slight_smile: It is very much appreciated. I understand how the dev clients work a lot more now.

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.