1

I'm trying add an env variable to my app without success:

  • I did yarn add dotenv

  • added an .env file in root with URL='https://mywebsite.com'

  • added to my app.js:

    const dotenv = require("dotenv") dotenv.config() console.log(process.env.URL);

and got undefined.

In my package.json I have "start": "./.env && react-scripts start",

And I deleted yarn.lock to get it into effect. Any help will be greatly appreciated

CoryCoolguy
  • 1,065
  • 8
  • 18

1 Answers1

0

I dont know if someone has a better solution but what worked was from this thread reactjs + yarn

  1. .env file and change URL='https://mywebsite.com' to REACT_APP_URL='https://mywebsite.com
  2. console.log(process.env.REACT_APP_URL)

Hope someone has a better solution

  • That’s the preferred way to do it, you don’t even need dotenv, check the docs https://create-react-app.dev/docs/adding-custom-environment-variables/ – ludwiguer Jun 21 '20 at 00:19