Closed
Description
Description
How the .env file and imports should be setup for the project correctly as currently the build is breaking.
Expected behavior
- add .env file with config in root
- npm install --save dotenv
- import dotenv using require('dotenv').config(); or ES6 syntax in index.js file
- consume using process.env.CONFIG_NAME across application
Actual behavior
Using the expected behaviour approach I get the above error. I've also tried both installing dotenv and not installing it (as ejecting the repository shows dotenv is already a dependency).
Environment
react-scripts@0.6.1
node - v6.6.0
npm - 3.10.8
Using a Chrome (53.0.2785.143) on a Mac.
Activity
zackify commentedon Oct 6, 2016
I'm trying to get this working too, I don't think you are supposed to actually install dotenv. For some reason env variables are not being imported from my .env file though.... so I am having a similar problem.
amilajack commentedon Oct 7, 2016
@zackify Are you on windows?
shrynx commentedon Oct 7, 2016
@georgelovegrove @zackify
Please have a look at this, for adding env variables.
https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables
zackify commentedon Oct 7, 2016
No. mac os sierra.
On Thu, Oct 6, 2016 at 22:28 Amila Welihinda notifications@github.com
wrote:
zackify commentedon Oct 7, 2016
Thanks but I have already. I have added the file. I'm using dotenv on other
projects and it works fine. In this case, I'm on the latest version of
create react app. Made a .env file at the root. Process.env is an empty
object in the app. Really weird for sure....
On Thu, Oct 6, 2016 at 22:29 Shriyans notifications@github.com wrote:
shrynx commentedon Oct 7, 2016
@georgelovegrove @zackify Is your os sierra too ? i am unable to reproduce it.
Also to add one more thing , in your .env file , what are the names of env variables. You have to append REACT_APP_ to them , to make it work.
eg:
This works.
and this doesn't
lovegrovegeorge commentedon Oct 7, 2016
I'm on OS Sierra but @shrynx made me look closer at the information I read before. I missed the appending 'REACT_APP_' to the start of the key. That's a bit of a verbose pain to add that to every key, could that not be shortened or removed entirely in the scripts?
Closing now, thanks for help.
gaearon commentedon Oct 7, 2016
It is intentionally verbose. Otherwise there is a risk of accidentally exposing a private key on the machine that happens to have the same name.
lovegrovegeorge commentedon Oct 7, 2016
@gaearon fair point, may be worth a one liner in the docs. p.s thanks for redux! aha
gaearon commentedon Oct 7, 2016
@georgelovegrove PRs are welcome to the docs 😉
lovegrovegeorge commentedon Oct 7, 2016
@gaearon Won't have the finesse to explain why that you will #juniordevforlife
gaearon commentedon Oct 7, 2016
But you know the right place to put it. We can polish the message later, PR is a start.
zackify commentedon Oct 7, 2016
Haha! Knew there had to be something simple. Agree, it's a little confusing
especially if you are used to setting up env files yourself.
On Fri, Oct 7, 2016 at 06:53 Dan Abramov notifications@github.com wrote:
17 remaining items