I am trying to deploy a React app on heroku and even though I have multiple environment variables set in heroku's config, none of them are appearing at run time. I added a console.log(process.env)
to my app and the output was this:
FAST_REFRESH: true
NODE_ENV: "production"
PUBLIC_URL: ""
WDS_SOCKET_HOST: undefined
WDS_SOCKET_PATH: undefined
WDS_SOCKET_PORT: undefined
My heroku config is this:
BACKEND_URL: https://lz-comparables-manager-be-stg.herokuapp.com/
NODE_ENV: staging
NODE_OPTIONS: --max_old_space_size=1024
SKIP_PREFLIGHT_CHECK: true
How come none of those variables (or any of the other normal env vars of a Node app) are showing up in the app?
CodePudding user response:
The prefix REACT_APP_ is necessary when accessing env variables, try
{process.env.REACT_APP_SOMETHING}
Also should you write prefix when define.
https://create-react-app.dev/docs/adding-custom-environment-variables/