Skip to content

Multi env troubleshooting

Kemal Ahmed edited this page Feb 12, 2024 · 15 revisions

They must all be at the same path. so if you specify { path: 'bob'}, your environment-specific variables must be at bob.development, bob.test, and bob.production. The environment-specific variables always overwrite the default values in your .env. If you omit one of these 3, then it won't be included but hopefully you have the default values.

Maybe even try setting your path config as { path: 'ios/.env' }, then let us know if this works.

Look at the react native CLI documentation for more on how to set it to the various Babel/Node environments.

This package now supports environment specific variables. This means you may now import environment variables from multiple files, i.e. .env, .env.development, .env.production, and .env.test.

The base set of variables will be .env and the environment-specific variables will overwrite them.

The variables will automatically be pulled from the appropriate environment and development is the default. The choice of environment is based on your Babel environment first and if it can't find that your NPM environment, which should actually be the same, but if the Babel environment isn't set it uses the NPM environment for robustness.

XCode

  • Configuration=Release => NODE_ENV=production
  • Configuration=Debug (default) => NODE_ENV=development

Read more about how to set that here: https://shockoe.com/ideas/development/how-to-setup-configurations-and-schemes-in-xcode/

Make sure you've given XCode full access to the hard drive:

  1. Select System Preferences->Security & Privacy->Full Disk Access
  2. + and add XCode

Android

Make sure to follow the Android signing guide before trying to build prod https://reactnative.dev/docs/signed-apk-android#adding-signing-config-to-your-apps-gradle-config

Android expo

React Native CLI

Regarding which environment you choose, this is from your CLI commands. By default, the CLI commands have NODE_ENV=development so to use production variables, it's a bit of specification.

  • react-native run-android --mode=release
  • react-native run-ios --mode=Release
  • react-native bundle --dev=false

Expo

Configure in eas.json

Reference Material

Clone this wiki locally