nx-react-native
nx-react-native copied to clipboard
NX Environment Variables
Are we able to access NX environment variables from the React Native JS bundle? I have an environment variable defined in .local.env
and I'm able to access it in my React & NodeJS apps in the same workspace. However, the same variable is undefined when I try to access it from the JS bundle during local development. The variable is defined if I print it out in metro.config.js
, so it seems to be available during build time.
@ceremonious You mean variables prefixed with NX_
? We can look into this support out of the box to keep things consistent with the rest of Nx plugins.
As a workaround, this babel plugin should work, but you have to maintain the list of variables yourself. https://www.npmjs.com/package/react-native-dotenv
https://www.npmjs.com/package/react-native-dotenv doesn't work as expected. We encountered following problems:
- Multiple environments don't work. We created .env.staging, tried to access it via APP_ENV=staging
- We have to make some change to .js file for new values to load whenever we change .env
Is there any other way, to pass different/new environment variables to react-native app?
No at this moment, I'll get someone to investigate this.
We ended up using - react-native-config
And we send env file using ENVFILE=.env.staging nx run-android investor-mobile
Hope this helps