DEV Community

Bret
Bret

Posted on

.env file not read

What causes a .env file not to be read? I have variables in it and apparently it’s not being read, I replaced the variables with passwords and it works.... soooo the variables loading is the problem. What causes that? I’m using react

Top comments (6)

Collapse
 
rafarochas91 profile image
Rafael Rocha

How are you running the application?
Are you setting them as variables in your machine? echo them from the bash to see if they are indeed being applied.
If you can't access anything in your .env please check the dotenv npm package.
Hope this helps!

Collapse
 
yobretyo profile image
Bret

How do I echo them? I have the env “ignored” because I’m using GitHub. I have the package installed. I’ve tried “REACT_APP” I front of all the variables as a test, still didn’t work

Collapse
 
rafarochas91 profile image
Rafael Rocha

hmm, thats indeed weird. Is your repo public by any chance?

Thread Thread
 
yobretyo profile image
Bret

No, it’s private. But I was told you still create variables

Thread Thread
 
rafarochas91 profile image
Rafael Rocha

Yes of course. Just meant it because if it was public I could check what was wrong. Echoing is just as easy as having a dummy script with echo $YOUR_ENV_VAR

Thread Thread
 
yobretyo profile image
Bret

I have a repo, but that project is private because I have API keys