5

I am building a React.js app with Firebase and cannot figure out why when I am running locally, console.log(process.env.NODE_ENV) in App.js always returns development, but when deploying to hosting it is always production.

In my .env file, I have NODE_ENV='production' or NODE_ENV='development', which I change before I build depending on which Firebase project alias I am deploying to. When I deploy to my Firebase development project, I always get the NODE_ENV to be 'production' because (I have read that) NODE_ENV gets set when npm building automatically. Is there a way for me to prevent this so when I deploy, it will stay as development? Or maybe I am doing this wrong? Anything helps, thanks!

.env

# Live
REACT_APP_FIREBASE_LIVE_API_KEY=..
REACT_APP_FIREBASE_LIVE_AUTH_DOMAIN=..
REACT_APP_FIREBASE_LIVE_DATABASE_URL=..

# Test 
REACT_APP_FIREBASE_TEST_API_KEY=..
REACT_APP_FIREBASE_TEST_AUTH_DOMAIN=..
REACT_APP_FIREBASE_TEST_DATABASE_URL=..

# Other
GENERATE_SOURCEMAP=false
NODE_ENV='production'
douglasrcjames
  • 1,133
  • 3
  • 17
  • 37
  • Does this answer your question? [Setting NODE\_ENV for firebase function](https://stackoverflow.com/questions/43139959/setting-node-env-for-firebase-function) – Aritra Chakraborty Mar 23 '20 at 21:42
  • 1
    @AritraChakraborty no, I am using the NODE_ENV in the React.js project directory only, not in my firebase functions. – douglasrcjames Mar 23 '20 at 21:57
  • I am running into the same problem.. I don't get at all the issue – Emixam23 Oct 24 '20 at 15:25
  • @Emixam23 I never got an answer to this, so maybe you can’t change that NODE_ENV variable – douglasrcjames Oct 25 '20 at 17:07
  • 1
    I found out that you can’t update this variable for some security against developers.. I found out that using ‘cmd-env’ was the answer at the end.. just make sure you build with the correct env file because it’s used at building time, not deploy/start/run time – Emixam23 Oct 25 '20 at 19:40

0 Answers0