Skip to content

Incompatible with expo-router #501

@brentvatne

Description

@brentvatne

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:

  1. Run npx create-expo-app
  2. cd my-app
  3. npm install react-native-dotenv
  4. Add the react-native-dotenv babel plugin
  5. Boot the app with npx expo start --ios
  6. 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.

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.

Metadata

Metadata

Assignees

Labels

wontfixThis will not be worked on

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions