Search code examples
reactjsfirebasedotenv

process.env.API_KEY is undefined


I am building a small application in react using firebase. I tried to put my firebase api key API_KEY=somekey in .env file which is in the root folder but when I use the process.env.API_KEY, I get an error in browser console shown in the picture below.

enter image description here

However, I have copied my api-key correctly in .env. what else could be the problem ?

Is there any configuration to be done in package.json before I use the process.env.API_KEY ?


Solution

  • Hy, here is the documentation explaining how to use env variables in react: link here.

    You must name your env variable REACT_APP_API_KEY in order to use it inside your react project.

    You can also check this response: response here .