-
-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed
Labels
Description
Is this a bug report?
yes
Can you also reproduce the problem with npm 4.x?
It's not an npm or yarn error
Which terms did you search for in User Guide?
custom environment variables
Environment
node -v
: 8.6.0npm -v
: 5.5.1yarn --version
(if you use Yarn): 1.3.2npm ls react-scripts
(if you haven’t ejected): 1.0.17
Then, specify:
- Operating system: macOS 10.11
- Browser and version (if relevant): chrome
Steps to Reproduce
As the documentation specified, front end environment variables can be defined by exporting them to the terminal, defining them on the start script of with a .env
file on the root.
My create-react-app is nested inside a backend express app with its own .env
. However, I have a .env
in the root of my front end app with REACT_APP_HOST=localhost
.
In App.js
, I console.log(process.env) and the only keys displayed are
{ NODE_ENV: 'development', PUBLIC_URL: '' }
It seems like its working for most other users and it may be that my app is nested but I'm unsure as to why environment variables defined in my .env
are not showing up.
// .env
REACT_APP_HOST=localhost
// App.js
....
componentDidMount() {
console.log(process.env);
}
// app structure
- fullApp
- create-react-app
- components
- App.js
- .env
- index.js
- .env
react-scripts@1.0.17