Like the title says, I have a static create-react-app that I'm deploying to Azure Static Apps with Azure DevOps. The problem is that absolutely none of the .env variables appear to be available on the frontend.
To be specific, I have an API key named REACT_APP_MAP_API_KEY
that I'm injecting using Pipelines on Azure Devops. I've confirmed that the key is loaded in from the variable group properly by logging it. This is my deployment pipeline YAML file:
trigger:
- main
pool:
vmImage: ubuntu-latest
variables:
- group: api-key-group
steps:
- task: CmdLine@2
inputs:
script: 'echo $(REACT_APP_MAP_API_KEY)'
- checkout: self
submodules: true
- task: AzureStaticWebApp@0
inputs:
app_location: '/'
api_location: 'api'
output_location: ''
env:
azure_static_web_apps_api_token: $(deployment_token)
REACT_APP_MAP_API_KEY: $(REACT_APP_MAP_API_KEY)
The key is echo'd when the pipeline runs. However, when I try to console.log the variable on the frontend using console.log(process.env.REACT_APP_MAP_API_KEY)
I simply get undefined
.
To the best of my knowledge, this is exactly how you're supposed to load an .env variable into a static app frontend on Azure, but it just appears to be flat out not working. Is this a bug on Azure's side?