create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

environment variables are not loading

Open stevegula opened this issue 9 years ago • 3 comments

Description

App is not reading in passed environment variables, from the .env file or from the command line ( %FOO=BAR npm start )

Expected behavior

I expect my app to have access to process.env.FOO

Actual behavior

JSON.stringify of process.env only provides these {"NODE_ENV":"development","PUBLIC_URL":""}

but my .env has: AWS_REGION=us-east-1 AWS_IDENTITY_POOL_ID=us-east-1:****************** AWS_USER_POOL_ID=us-east-1_************* AWS_USER_POOL_ARN=arn:aws:cognito-idp:us-east-1:*************:userpool/us-east-1_*************** AWS_USER_POOL_CLIENT_ID=*******************************

Environment

Run these commands in the project folder and fill in their results:

  1. npm ls react-scripts (if you haven’t ejected): 0.8.4
  2. node -v: 6.9.2
  3. npm -v: 4.0.3

Then, specify:

  1. Operating system: LinuxMint 18
  2. Browser and version: Chrome 55.0.2883.87 (64-bit)

Reproducible Demo

% create-react-app test % cd test % echo "AWS_REGION=us-east-1" >> .env % sed -i 's/reload./reload. <br/>{JSON.stringify(process.env)}/' src/App.js % npm start Notice that only {"NODE_ENV":"development","PUBLIC_URL":""} get displayed.

stevegula avatar Dec 15 '16 01:12 stevegula

Hi, you should define your env. variables using the prefix REACT_APP instead AWS_REGION it must be REACT_APP_AWS_REGION

https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables

https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/config/env.js#L20

eperedo avatar Dec 15 '16 02:12 eperedo

dammit. I read those docs repeatedly and missed that line. and even asked in IRC first before posting here. I knew if I asked I'd be proven user error. Thanks @eperedo .

stevegula avatar Dec 15 '16 03:12 stevegula

👍 Glad it resolved! We did it this way to avoid security risks.

gaearon avatar Dec 15 '16 13:12 gaearon