I cannot use my environment variables on my development (localhost) with ReactJS.
I made sure of following:
- My .env file is in the root directory
- My env variable has a prefix of
REACT_APP_*
and the usage isprocess.env.REACT_APP_*
- My env variable does not contain
''
and contains=
as well as it does not contain;
or,
so the definition isREACT_APP_SOMETHING = something
- Restarted server multiple times by ctrl + c and yarn start
- I checked (and copied & pasted) all the variable names to make sure and avoid misspelling
Even after all of this if I try to use them (for example with console.log(process.env.REACT_APP_SOMETHING)
) it prints only undefined. Is there anything that has to be done in package.json
scripts? The definition is only:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
I used create-react-app to initialize my project.
Printing for example console.log(process.env.NODE_ENV)
works fine. I tried even creating .env.development file with no luck.