I have a ReactJS project that I have been deploying to GitLab Pages for a while without any issues. Today however I started using .env
files to get the app name and app version from the package.json
file.
REACT_APP_VERSION=$npm_package_version
REACT_APP_NAME=$npm_package_name
When I deployed the app again, any references to either process.env.REACT_APP_VERSION
or process.env.REACT_APP_NAME
shows undefined
although it works on my dev machine. I looked at the artifacts and it does have the .env
file under the public/
directory.
Here's my .gitlab-ci.yml
file that I use to deploy the app to GitLab Pages:
stages:
- build
- deploy
build:
image: node:16.15-buster-slim
stage: build
script:
- yarn install
- yarn build
- cp .env.example build/.env
artifacts:
paths:
- build/
pages:
image: alpine:latest
stage: deploy
variables:
GIT_STRATEGY: none # Do not clone git repo
NODE_ENV: production
PUBLIC_URL: https://somedomain.com
script:
# Rename the CRA `build` folder to `public`
- mv build public
- cp public/index.html public/404.html
artifacts:
paths:
- public