Environment variables not being read
See original GitHub issueIf you are reporting a bug, please fill in below. Otherwise feel free to remove this template entirely.
Can you reproduce the problem with latest npm? yes
Description
Setting environment variables with the REACT_APP_
prefix is supported according to the documentation. I have tried setting via cli: REACT_APP_FOO=1 npm start
and .env
file, and both methods fail to set process.env
inside the built file.
Expected behavior
The REACT_APP_
prefixed environment variables should be available in development and production builds of my app.
Actual behavior
process.env
is an empty object inside my app.
Environment
Run these commands in the project folder and fill in their results:
npm ls react-scripts
(if you haven’t ejected): react-scripts@0.9.4node -v
: v7.6.0npm -v
: 4.3.0
Then, specify:
- Operating system: Max OSX 10.11.6 (El Capitan)
- Browser and version: Chrome 56.0.2924.87 (64-bit)
Reproducible Demo
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
5 reasons why your .env environment variables don't work
1. Your framework doesn't automatically load .env files. · 2. You added or otherwise updated your .env file after starting your server. ·...
Read more >Problems with Environment Variables
If the error message states that the environment variable is not set, IT MEANS PRECISELY THAT ! The most likely reason is that...
Read more >.env Not Reading Variables Sometimes - Laracasts
I have the User $tz variable being set to this using getenv('DISPLAY_TZ')?:date_default_timezone_get() and then used by calling setTimezone(Auth::user()->tz) on ...
Read more >can't read environment variables in create-react-app ...
Create .env.development text file. Then you can list variables there, but all of them must start with REACT_APP_ prefix.
Read more >Environment Variables,System variables are not accessible
Open Run (Windows Key + R), type in rundll32 sysdm.cpl,EditEnvironmentVariables and hit enter. Under either the "User Variables" or "System ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, I’m getting this same issue now. I’m using the key
REACT_APP_SECRET_CODE
but when I log it into the console, it shows up empty/undefined:console.log(process.env.REACT_APP_SECRET_CODE)
.I’m using this version:
"react-scripts": "^1.0.17"
I just wasted a whole hour trying to debug the code because I noticed process.env was empty. Please update the docs so this is more explicit. Thanks 😃