Why does process.env not see my environments from the .env file? I already added REACT_APP_API_KYE = 'some-code-example'
in the file, but when I try to use it in the api request, all apps are down. I did restart my app after creating the .env file.
.env
REACT_APP_API_KEY = 'euk4h43l-ertek8-rgde45-gkr3945';
.common.api.ts
export const instance = axios.create({
baseURL: 'xxxxxxx',
withCredentials: true,
headers: {
'API-KEY': process.env.REACT_APP_API_KEY
}
})
2
Answers
Have you added the
dotenv
package to yourpackage.json
, and calleddotenv.config()
at the beginning of your script?you need to install
after this add to your app.