To access REACT_APP_* environment variables within the React app deployed on Azure app services

Rajashri Udhoji 0 Reputation points
2023-09-11T14:30:31.2733333+00:00

Hello,

I tried below ways to read REACT_APP_* variables on the React App deployed on App service:

  1. Add all the REACT_APP_* to App service -> Configuration -> Application settings : Read the variables within React app as process.env.REACT_APP_*
  2. Add them to the Azure devOps release pipeline : Read the variables within React app as process.env.REACT_APP_
    User's image
  3. Pass the variables to Yml script via Variable group , secure files.

Deployment to App service using Azure devops is successful however, the environment variables are not getting passed.

Kindly help me with the correct way to solve this environment variable issue.

Thanks,
Rajashri

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,663 questions
{count} votes

2 answers

Sort by: Most helpful
  1. ajkuma 25,781 Reputation points Microsoft Employee
    2023-09-12T20:36:28.2266667+00:00

    Update: @Rajashri Udhoji - was able to solve the env issue by adding variables to the build pipeline.

    Based on my understanding of your scenario description, you have tried 3 approaches to set environment variables in Azure App Service for react app.

    If you are building for production to generate the /build locally and then deploying with the /build folder to Azure, verify that the environment variables are accessible in your local environment so they are injected during build time.

    Kindly checkout this doc section for the steps : Environment variables are missing after deployment. - Also, checkout note - For more information on how React uses and expects environment variables.

    Just to highlight, also add REACT_APP_MY_ENV_VAR for MY_ENV_VAR. The variable can be accessed using process.env.REACT_APP_MY_ENV_VAR.

    Find this sample at https://github.com/Azure-Samples/js-e2e-web-app-server-auth/blob/main/appSettings.js for alternative approach.

    Also, checkout this discussion thread: https://stackoverflow.com/a/75208784/8194837

    If you're still having issues with passing environment variables to your app, please provide more details about the error message or exact behavior you're experiencing.

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.