react-native-dotenv icon indicating copy to clipboard operation
react-native-dotenv copied to clipboard

How to reset the env variables?

Open PolGuixe opened this issue 7 years ago • 9 comments

How can I change the variables in the .env file and see the changes immediately?

PolGuixe avatar Jun 15 '17 20:06 PolGuixe

According to the docs, make a change to the file importing the variables and you'll see the change immediately; even whitespace works.

alizahid avatar Jul 09 '17 01:07 alizahid

@alizahid this approach doesn't work for me.

KirillPd avatar Nov 03 '17 13:11 KirillPd

this works for me

kanso-git avatar Dec 20 '17 22:12 kanso-git

it doesnt work for me

DoWhileGeek avatar Jul 17 '18 00:07 DoWhileGeek

doesn't work for me

jameskennethrobinson avatar Aug 10 '18 21:08 jameskennethrobinson

Just to be clear, here are the steps;

  1. Update .env
  2. Go to file which is importing the variable; import { MY_VAR } from 'react-native-dotenv'
  3. Make some changes to the file; any change will do. If Git recognizes a change, it should do the trick
  4. Save the file
  5. Reload in simulator / device
  6. Profit

Sometimes, step 4 can be a bit tricky. Eg, my editor removes unnecessary whitespace on save. So I have to be careful where I add spaces for it to register as a change. But otherwise, this has worked flawlessly for me.

@PolGuixe @KirillPd @kanso-git @DoWhileGeek @jameskennethrobinson Hope this helps!

alizahid avatar Aug 23 '18 11:08 alizahid

npm start -- --reset-cache . This worked for me . Sometimes I make the variable name wrong in the .env file just to verify.

pradhul avatar Mar 18 '19 09:03 pradhul

⬆️ After finished to reset cache, to reload the app the press "r". This worked for me.

ykws avatar Mar 26 '20 12:03 ykws

I don't think there is a consistent answer to this.

Modified steps using Expo

  • Update .env
  • Go to EVERY file which is importing the variable; import { MY_VAR } from 'react-native-dotenv'
  • Make some changes to EVERY file which is importing the variable; any change will do. If Git recognizes a change, it should do the trick
  • Save the file
  • Restart metro bundler (hit r in terminal where expo start is running
  • Reload in simulator / device
  • Cringe

kerkness avatar Apr 04 '20 11:04 kerkness