-
-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REACT_APP_* custom variables in .env* are undefined in development #3568
Comments
It doesn't look up your directory tree into Please make sure it's in the correct file. |
If you exported |
I have not. In fact, |
Actually I have found out the reason why. I did not realize that the environment variables are injected in build-time. (Don't know why I assumed they would be accessible in dev) Thanks for your help though. |
So you can't use them in development ?!? |
Yes, you can. Are you experiencing behavior otherwise? If so, please file a new issue. |
Having the same problem on my hackintosh (OSX 10.11.6) But the same project/code does work on my MacBook Pro (macOS 10.13.6) |
@jeroenhoebe I am having the same issue em MacBook here! |
Re-starting the server may resolve the issue for most (If .env files were created while server was running)
|
Having a similar issue with .env.development and .env.production custom env files - REACT_APP* env vars are undefined in my React code. However, .env is working properly and my REACT_APP* env vars are properly exposed in my React code. mac OS High Sierra v 10.13.6 Additionally, I can verify the existence of these three files and their env var values via $cat .env.development and $cat .env.production and $ cat .env This CRA app is a nested React app inside a node/express server directory. There are no .env, or .env* files in the root server directory. The .env, .env* files are in the root CRA app directory only. Restarting server, closing IDE or clearing Browser cache does not remedy things. |
You should not put your env files in the src folder, put it in the folder above.. ;) |
the same problem, I have restarted server, but variable is still undefined |
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.17Then, specify:
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 withREACT_APP_HOST=localhost
.In
App.js
, I console.log(process.env) and the only keys displayed areIt 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.react-scripts@1.0.17
The text was updated successfully, but these errors were encountered: