environment variables are not loading
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:
npm ls react-scripts(if you haven’t ejected): 0.8.4node -v: 6.9.2npm -v: 4.0.3
Then, specify:
- Operating system: LinuxMint 18
- 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.
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
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 .
👍 Glad it resolved! We did it this way to avoid security risks.