I'm trying to use environment variables in ReactApp deploying at Github-pages.
The variable is added through process.env and starts with REACT_APP as docs prescribe
export default class WeatherService {
constructor() {
this.API_WEATHER_URL = process.env.REACT_APP_DEV_SERVER_URL + 'api/weather';
}
and .env created with GitHub Actions yml
jobs:
front-build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Store variables
run: |
cd front-app
touch .env
REACT_APP_DEV_SERVER_URL=${{ secrets.DEV_SERVER_URL }} >> .env
- name: Build
run: |
cd front-app
npm install
npm run-script build
- name: Deploy
...
but the app gets wrong values from GitHub Secrets.
see the react-app at GH-pages receives a wrong object, not what i've passed ("username.cloudTech.com/api"):
this.API_BLOB_URL = Object({
NODE_ENV: "production",
PUBLIC_URL: "/azure-flask-react",
WDS_SOCKET_HOST: void 0,
WDS_SOCKET_PATH: void 0,
WDS_SOCKET_PORT: void 0,
FAST_REFRESH: !0
}).REACT_APP_DEV_SERVER_URL + "api/blob/"
At the same time when I build locally with npm run build. React successfully replaces the env. variables
As used to the purpose is to use different environment settings as api dev server in
- development (127.0.0.1:5000) and
- production (username.cloudTech.com/api).
I've already tried to use env-cmd and dotenv lib but it neither worked
UPDATE:
If I pass REACT_APP_ENV='username.cloudTech.com/api' npm script - it passes this variable successfully:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build:staging": "REACT_APP_FRONT_APP_URL=nikonov91-dev.github.io/azure-flask-react/ npm run build"
...
}
And then voila.
UPDATE on @OldPro`s answer. I've quoted my line:
run: |
cd front-app
touch .env
echo 'REACT_APP_DEV_SERVER_URL=${{ secrets.DEV_SERVER_URL }}' >> .env
but the value is still empty in JS ch:

I've tried also the answer of @peterevans
run: |
cd front-app
echo "DEV_SERVER_URL=${{ secrets.DEV_SERVER_URL }}" >> $GITHUB_ENV
touch .env
echo "REACT_APP_DEV_SERVER_URL=${{ env.DEV_SERVER_URL }}" >> .env
unfortunately the variable is the same
UPDATE
I'm sure my approach is working because if I hardcode the variable in YML it works as should and can be easily accessed in my Appv
- name: Store variables
run: |
cd front-app
touch .env
echo "REACT_APP_DEV_SERVER_URL='https://first-py-app.azurewebsites.net/'" >> .env
and
this.API_BLOB_URL = process.env.REACT_APP_DEV_SERVER_URL + 'api/blob/';
becomes
this.API_BLOB_URL = "https://first-py-app.azurewebsites.net/api/blob/"
BUT I STILL LOOKING FOR solution how to pass variable from GH-Secrets



