Azure cant access env variable in react web app

Viewed 2016

I saw there was a similar question to this a few years ago, but the hyperlink answer has been closed by microsoft.

I have a react app created using create-react-app. It has been deployed already to heroku and loads in some environmental variables to access google maps etc. This all work just fine for heroku.

I have taken this code and pretty much followed the instructions here: https://docs.microsoft.com/en-gb/azure/app-service/app-service-web-get-started-nodejs I basically uploaded a zip of my 'npm run build' using kudu.

I can see that the web app is online and is being served by azure. But the environmental variables I set up in the portal are not being read by my app, causing it to crash, even though I can see them in kudu. when i try to console.log process.env I get {NODE_ENV:"production",PUBLIC_URL:""}, but see none of the varaibles that I can see in kudu.

If I try to log a specific variable I get back 'undefined' Does anyone know what Im doing wrong?

1 Answers

Within Azure: Instead of MY_ENV_VAR, use REACT_APP_MY_ENV_VAR

Within React: Instead of process.env.MY_ENV_VAR, use process.env.REACT_APP_MY_ENV_VAR

Hope this helps

Related