-
-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Describe the bug
Cross-posting from the Expo repository: expo/expo#28933
So what's happening here is that react-native-dotenv is agressively inlining all environment variables from the machine in the bundle. This has 2 side effects that cause the behavior we are seeing:
It precedes the babel-preset-expo/src/expo-router-plugin.ts transformation, causing important settings of Expo Router to be overwritten. (this file)
In the system environment (outside the bundle), there is an environment variable with the same name used as the require.context within Expo Router. It's from the type generation, and uses the absolute path we are seeing here (generated here, set as process.env here)react-native-dotenv seems to do some internal evaluation (possibly due to static rendering, since we evaluate bundle code). Even when setting safe or allowlist / blocklist, it seems to pollute/mutate all environment variables
To Reproduce
Steps to reproduce the behavior:
- Run
npx create-expo-app cd my-appnpm install react-native-dotenv- Add the react-native-dotenv babel plugin
- Boot the app with
npx expo start --ios - Notice that you see "Welcome to Expo" screen rather than the routes in
/app(without the plugin, you will see tabs and theapp/(tabs)/index.tsxscreen.
https://github.com/brentvatne/repro-dotenv
Expected behavior
react-native-dotenv should play nicely with expo-router.
Screenshots
n/a
Desktop (please complete the following information):
- OS: any
- Browser: any
- Version: any
Smartphone (please complete the following information):
- Device: any
- OS: any
- Browser: any
- Version: any
Additional context
Given this incompatibility, we are currently recommending that developers using Expo Router use Expo CLI's built-in environment variable support.
I think that one way to fix this issue would be to change the default behavior to whitelisted env vars only. In my opinion, not having this default can be a footgun.