问题
I am trying to use environment variables in a react app created on WSL. I cannot access the variables from my app. Here is what I did:
- Create a
.env
file at the root folder of my react app (within a client folder of a Rails app) - Create a variable:
REACT_APP_API_URL=http://localhost:3000/api/v1/
- Log the variable in my console:
console.log(process.env.REACT_APP_API_URL)
- Restarted the server
I keep getting an undefined variable.
Am I missing anything related to WSL maybe? I am a bit clueless as I cannot find a similar problem online.
Thank you!
回答1:
I think your file is in the wrong directory. See here: Environment variables are always undefined in VueJs application (possible duplicate of your question).
来源:https://stackoverflow.com/questions/61371041/why-my-environnement-variables-not-picked-up-with-create-react-app