Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Environment variables not being read

See original GitHub issue

If 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


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.


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

  1. npm ls react-scripts (if you haven’t ejected): react-scripts@0.9.4
  2. node -v: v7.6.0
  3. npm -v: 4.3.0

Then, specify:

  1. Operating system: Max OSX 10.11.6 (El Capitan)
  2. Browser and version: Chrome 56.0.2924.87 (64-bit)

Reproducible Demo

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

reilgcommented, Jul 19, 2018

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"

atlantehcommented, Jan 16, 2019

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found