Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expo application doesn't get changes in .env file

I have an Expo managed react native application. I created my .env file in the root of my project, installed react-native-dotenv and set up babel to use it. After a while I managed to get it to work.

I have my environment variable ENDPOINT=http://127.0.0.1:8000/api

and i use it with process.env.ENDPOINT

After a while I decided to test the android version of the app, so i changed the endpoint url to my LAN ip and restarted the server. The problem is that even after restarting the server, the cache and the computer, when I call process.env.ENDPOINT it keeps the first url I set.

Here's a list of the things i tried:

  • restarting the server
  • restarting the server and the cache
  • restarting the whole computer
  • change the variable name to REACT_APP_ENDPOINT as many suggested (I get undefined, it's still stuck to ENDPOINT)
  • empty expo cache

The strange thing is that I already changed that same variable twice (from 127.0.0.1:8000 to 127.0.0.1:8080 and back for a problem with backend) and had the same problem, but it went away by itself after a couple of minutes (and server restarts). This time I've been trying to get it to work for 7 hours and nothing has changed.

Any idea?

like image 837
Fabio R. Avatar asked Oct 23 '25 15:10

Fabio R.


2 Answers

I had the same issue and managed to run the app with .env changes after using the following command.

expo r -c

reference: https://github.com/goatandsheep/react-native-dotenv/issues/75#issuecomment-728055969

like image 98
Sisila Priyankara Avatar answered Oct 25 '25 12:10

Sisila Priyankara


You can run:

npx expo start --clear

It will clear the cache from the bundler and then you'll be able to run it.

like image 34
kankdesai Avatar answered Oct 25 '25 11:10

kankdesai