Why my environnement variables not picked up with create React app?

白昼怎懂夜的黑 提交于 2020-04-30 06:26:20

问题


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:

  1. Create a .env file at the root folder of my react app (within a client folder of a Rails app)
  2. Create a variable: REACT_APP_API_URL=http://localhost:3000/api/v1/
  3. Log the variable in my console: console.log(process.env.REACT_APP_API_URL)
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!