expo: expo SDK 49 does not load custom env file
Minimal reproducible example
https://github.com/dooboolab-community/expo-router-starter/pull/5
Summary
In expo SDK 48, it was possible to load custom .env file with dotenv -e .env.prod -- expo start. However, from SDK 49, it does not work.
You may try working example in https://github.com/dooboolab-community/expo-router-starter main branch and not working example in https://github.com/dooboolab-community/expo-router-starter/pull/5.
I setup .env and .env.prod with below variables.
For .env,
ROOT_URL=localhost:3000
For .env.prod
ROOT_URL=localhost:5050
SDK 48 results
- yarn start
- yarn start:prod
SDK 49 results
-
yarn start
-
yarn start:prod
Environment
expo-env-info 1.0.5 environment info:
System:
OS: macOS 13.4.1
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
Yarn: 3.6.0 - ~/.nvm/versions/node/v18.15.0/bin/yarn
npm: 9.7.2 - ~/.nvm/versions/node/v18.15.0/bin/npm
Watchman: 2023.07.10.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.12.1 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8815526
Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
npmPackages:
@expo/webpack-config: ^18.1.2 => 18.1.2
expo: ^49.0.5 => 49.0.5
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.72.3 => 0.72.3
react-native-web: ~0.19.7 => 0.19.7
npmGlobalPackages:
eas-cli: 3.16.0
Expo Workflow: managed
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 1
- Comments: 20 (7 by maintainers)
Commits related to this issue
- chore: resolve custom .env in expo 49 https://github.com/expo/expo/issues/23727\#issuecomment-1651609858 — committed to dooboolab-community/expo-router-starter by hyochan a year ago
- chore: resolve custom .env in expo 49 https://github.com/expo/expo/issues/23727\#issuecomment-1651609858 — committed to dooboolab-community/expo-router-starter by hyochan a year ago
- chore: resolve custom .env in expo 49 https://github.com/expo/expo/issues/23727\#issuecomment-1651609858 — committed to dooboolab-community/expo-router-starter by hyochan a year ago
Would be very practical to allow for custom env files if possible. In our case, we have a staging environment for which we’d like to have a
.env.stagingbut make it behave as if theNODE_ENVwas production and also a qa environment with.env.qa. In our previous app, we had to use a hacky setup like proposed above but I’d much rather have something working out of the box for supporting custom environments other than development, test and production. Definitely a very nice step in the good direction for the environment variables with SDK 49 though.I get a weird result as well the env vars work on
ios/androidbut on web they are undefined 🤔 is there a solution for this ?maybe totally unrelated but when I build
expo run:ios --configuration Releaseit says the.envis loaded when first running command but they are undefined at run time. exact same command without--configuration Releaseworksedit:
After messing with
.envsome more it seems like it’s wayyy more trouble than it’s worth and I’m not convinced it’s actually stable. Seems to not work in some cases, makes things less type safe, behavior witheas updateseems inconsistent. Also, when using CI it’s required to generate a.envfile during the action which is a pain.Maybe I’m just dumb, but all these problems can be easily solved by just hardcoding the environment variable values and switching based in the
eas.jsonupdates channel.If you call the files .env.development and .env.production it works out of the box now in SDK 49.
Expo will load the production one automatically when you set NODE_ENV=production before you start the server. If you still need to load custom ENV files (even in EAS), with custom naming, hit me up. It’s possible but some changes are needed.