You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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-app
npm 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 the app/(tabs)/index.tsx screen.
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.
Reacted by Pape THIAM, Ahmed Eid, Yassine Amjad, Everton Nogueira, Renan Ramos, Hugo Castro, Marko Ugrenovic and TimotheBerthier
To provide some more context, Expo uses internal environment variables that are not considered public (and therefore should never end up in the bundle). If these variables can be left untouched, we should have a way to get Expo Router and react-native-dotenv to work together.
Basically, all EXPO_* variables should be left alone, with the gray area being EXPO_PUBLIC_* variables. This is mostly defined by users using the default .env integration in Expo.
This babel plugin is meant to be simple and non specific. React native dotenv is meant to encourage best practices and you're welcome to go around this using blocklist. Expo-variables is a great alternative, but I'm not sure this is a fault of the library just yet. If you can provide a sample I'd be happy to take a look.
Yeah, I'm not exactly sure what's going on. In Expo, we do some bundling and possible static rendering (basically evaluating parts of bundle code in Node). Not sure if that might have anything to do with it. So far, neither safe + path, blocklist, or allowlist worked for me, unclear why.
It would be nice if this library can work in Expo, if users need more control over it.
I was facing the same problem. FYI, the incompatibility of react-native-dotenv with expo-router can load a default screen of expo, and not your normal dev app you're building.
@brentvatne in expo we don't have the ability to load arbitrary .env files. for example .env.qa or .env.staging you can only load standard .env files .env.production, .env.test or .env.development.
however with RN dotenv, we're able to do so use the APP_ENV env variable.
I was facing the same problem. FYI, the incompatibility of react-native-dotenv with expo-router can load a default screen of expo, and not your normal dev app you're building.
+1 here, our app is dependent on this package for reasons outlined by @a-eid. Is there something in the works for a fix?
Would love to update to expo 51 asap.
After closer analysis, there are some fundamental concerns that this will cause errors. I will have to spend more time on the weekend figuring out how to fix this
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Reacted by Marko Ugrenovic, Robin Scharf, Samuel, Arman Mamyan and aaron
Activity
github-actions commentedon May 16, 2024
Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/501
byCedric commentedon May 16, 2024
To provide some more context, Expo uses internal environment variables that are not considered public (and therefore should never end up in the bundle). If these variables can be left untouched, we should have a way to get Expo Router and react-native-dotenv to work together.
Basically, all
EXPO_*variables should be left alone, with the gray area beingEXPO_PUBLIC_*variables. This is mostly defined by users using the default .env integration in Expo.goatandsheep commentedon May 17, 2024
Does it work if you add these to blocklist? I'm happy to add this hint to docs if it works.goatandsheep commentedon May 17, 2024
This babel plugin is meant to be simple and non specific. React native dotenv is meant to encourage best practices
and you're welcome to go around this using blocklist. Expo-variables is a great alternative, but I'm not sure this is a fault of the library just yet. If you can provide a sample I'd be happy to take a look.goatandsheep commentedon May 17, 2024
My bad I didn't see you provided a repro project. I'm taking a look now
goatandsheep commentedon May 17, 2024
I also didn't read that blocklist didn't work for you. That is concerning.
byCedric commentedon May 17, 2024
Yeah, I'm not exactly sure what's going on. In Expo, we do some bundling and possible static rendering (basically evaluating parts of bundle code in Node). Not sure if that might have anything to do with it. So far, neither
safe+path,blocklist, orallowlistworked for me, unclear why.It would be nice if this library can work in Expo, if users need more control over it.
danicunhac commentedon May 22, 2024
I'm having the same problem and since my project is still under development I've unshifted
EXPO_PUBLIC_to my env variables, as specified in https://docs.expo.dev/guides/environment-variables/.mayel15 commentedon Jul 2, 2024
I was facing the same problem. FYI, the incompatibility of
react-native-dotenvwithexpo-routercan load a default screen ofexpo, and not your normal dev app you're building.As an alternative for
react-native-dotenv, they're the default Expo CLI's built-in environment variable support or react-native-config for bare react native app.a-eid commentedon Jul 3, 2024
@mayel15 unfortunately expo's built in env variables is not ideal, rn dotenv is way better.
brentvatne commentedon Jul 16, 2024
@a-eid - can you explain the limitations that you're encountering? you could try disabling them, i'm not sure if that will help here though: https://docs.expo.dev/guides/environment-variables/#disabling-environment-variables
a-eid commentedon Jul 17, 2024
@brentvatne in expo we don't have the ability to load arbitrary .env files. for example
.env.qaor.env.stagingyou can only load standard .env files.env.production,.env.testor.env.development.however with RN dotenv, we're able to do so use the
APP_ENVenv variable.robin-scharf commentedon Sep 2, 2024
+1 Fortunately, I was able not to depend on react-native-dotenv.
cchoi94 commentedon Sep 10, 2024
+1 here, our app is dependent on this package for reasons outlined by @a-eid. Is there something in the works for a fix?
Would love to update to expo 51 asap.
2 remaining items
tiavina-mika commentedon Jan 14, 2025
@cchoi94 's solution works, thanks.
When will it be implemented in the main repository?
goatandsheep commentedon Jan 14, 2025
I am reading this now. Will review and help with merge today
goatandsheep commentedon Jan 14, 2025
Ok i took a look at the code. Will require minor cleanup but overall looks awesome. Will be merging in today.
goatandsheep commentedon Jan 14, 2025
After closer analysis, there are some fundamental concerns that this will cause errors. I will have to spend more time on the weekend figuring out how to fix this
samuelpeybernes-dev commentedon Jan 26, 2025
Is there some news about the fix implementation in the main repository?
david-bermejo commentedon Mar 10, 2025
Hi @goatandsheep, have you had a chance to spend more time on this issue? It's fantastic, and I’d love to continue using it alongside expo-router
stale commentedon Jun 27, 2025
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
github-actions commentedon Jul 23, 2026
Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/501
test for #501
motdotla commentedon Jul 28, 2026
Hey everyone,
This is fixed in
v4.1.0and greater. Thank you for using react-native-dotenv!cc @brentvatne @david-bermejo @samuelpeybernes-dev @tiavina-mika @mayel15 @byCedric