-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure Static Web Apps Environment Variable Not Working #1579
Comments
It's not working for me either, but looking at the docs, seems that it's not supposed to work like this. |
I’ve been struggling to access environmental variables in my app for the past two days, with no success. After some investigation, I realized that the secrets I was looking at weren’t Azure environment variables but GitHub secrets. This raises the question: what’s the point of having environment variables in Azure if we can’t access them as easily as we can Azure App Service settings for different application environments? my yaml file
I had to save these secrets in GitHub action secrets |
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:
Verified that the environment variables are correctly set in the Azure Static Web Apps settings.
Ensured that variables have the required prefixes, as per Create React App requirements.
Triggered redeployments to rule out potential caching issues.
Confirmed that the environment variables are accessible locally with .env.
Additional Details:
To Reproduce
Steps to reproduce the behavior:
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):
The text was updated successfully, but these errors were encountered: