Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

NX Environment Variables #32

Open
ceremonious opened this issue Jan 11, 2021 · 4 comments
Open

NX Environment Variables #32

ceremonious opened this issue Jan 11, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@ceremonious
Copy link

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.

@jaysoo
Copy link
Member

jaysoo commented Jan 15, 2021

@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

@jaysoo jaysoo added the enhancement New feature or request label Jan 15, 2021
@jaysoo jaysoo self-assigned this Jan 15, 2021
@rjvim
Copy link

rjvim commented Jan 30, 2021

https://www.npmjs.com/package/react-native-dotenv doesn't work as expected. We encountered following problems:

  1. Multiple environments don't work. We created .env.staging, tried to access it via APP_ENV=staging
  2. 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?

@jaysoo
Copy link
Member

jaysoo commented Feb 10, 2021

No at this moment, I'll get someone to investigate this.

@rjvim
Copy link

rjvim commented Feb 11, 2021

We ended up using - react-native-config

And we send env file using ENVFILE=.env.staging nx run-android investor-mobile

Hope this helps

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants