Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
330 stars 57 forks source link

Azure Static Web Apps Environment Variable Not Working #1579

Open Temesgenzewude opened 2 hours ago

Temesgenzewude commented 2 hours ago

Describe the bug

I'm deploying a React app with Azure Static Web Apps and have configured environment variables in the Azure Portal under Configuration > Environment variables. However, these variables are not being injected into the app during deployment.

In the deployed app:

Logging process.env shows that the expected environment variables are undefined. When referencing these variables directly in index.html for testing, they remain as placeholders (e.g., %VARIABLE_NAME%) instead of being replaced with their actual values, suggesting they aren’t injected during the build. The environment variables work correctly when I use a .env file locally, so this issue appears specific to the Azure Static Web Apps deployment.

Troubleshooting Steps Taken:

Additional Details:

To Reproduce Steps to reproduce the behavior:

  1. Set up a React application deployed through Azure Static Web Apps.
  2. Add the environment variable REACT_APP_API_URL in the Azure Static Web App settings under Configuration > Environment variables.
  3. Deploy the application through GitHub Actions as per the default workflow setup by Azure.
  4. Log process.env.REACT_APP_API_URL in the application code (or %REACT_APP_API_URL% in index.html for testing) to check the value of the environment variable.

Expected behavior The environment variable REACT_APP_API_URL should be accessible in my React application as process.env.REACT_APP_API_URL, displaying the value set in the Azure Portal configuration.

Device info (if applicable):

Temesgenzewude commented 2 hours ago

@juliamuiruri4