1

First variable in .env file available to use, but can't use other variables.

.env file;

REACT_APP_PORT=44318
APP_BASE_URL=https://localhost:44318/

printed process.env content in console via code below;

export default () => {
    useEffect(() => {
        console.log('object', process.env)
    })

This is what I see;

enter image description here

pcakage.json scripts;

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
TyForHelpDude
  • 4,828
  • 10
  • 48
  • 96
  • Try prefixing it with REACT_, what starter are you using? – Borjante Jun 29 '20 at 14:33
  • 3
    You need to add `REACT_APP_` as prefix when using CRA, use [this answer](https://stackoverflow.com/questions/49579028/adding-an-env-file-to-react-project/49579700#49579700) – tarzen chugh Jun 29 '20 at 14:35

1 Answers1

3

Note: You must create custom environment variables beginning with REACT_APP_. Any other variables except NODE_ENV will be ignored to avoid accidentally exposing a private key on the machine that could have the same name. Changing any environment variables will require you to restart the development server if it is running.

So prefixing all your custom variables with REACT_APP_ and rebooting should work.

Borjante
  • 9,767
  • 6
  • 35
  • 61