# Environments in Create React App

**URL:** <https://discourse.sst.dev/t/environments-in-create-react-app/30>\
**Category:** Chapter Comments\
**Created:** [May 9, 2018, 6:39pm UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30 "2018-05-09T18:39:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 6:39pm UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/1 "2018-05-09T18:39:09Z")

</div>

_From @jayair on Fri Dec 01 2017 18:45:01 GMT+0000 (UTC)_  
  
Link to chapter - [https://serverless-stack.com/chapters/environments-in-create-react-app.html](https://serverless-stack.com/chapters/environments-in-create-react-app.html)  
  
_Copied from original issue: [https://github.com/AnomalyInnovations/serverless-stack-com/issues/168](https://github.com/AnomalyInnovations/serverless-stack-com/issues/168)_

---

<div class="post-metadata">

**Author:** ![dsherida](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/dsherida/32/264_2.png) [@dsherida](https://discourse.sst.dev/u/dsherida)\
**Post date:** [October 14, 2018, 5:19am UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/2 "2018-10-14T05:19:56Z")

</div>

It should probably be noted at the top of this section that this tutorial relates to the project completed in Part I.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [October 14, 2018, 5:13pm UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/3 "2018-10-14T17:13:24Z")

</div>

Good point. I’ll add a note.

---

<div class="post-metadata">

**Author:** ![enzigma-kunal-ramtek](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@enzigma-kunal-ramtek](https://discourse.sst.dev/u/enzigma-kunal-ramtek)\
**Post date:** [April 3, 2019, 8:57am UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/5 "2019-04-03T08:57:51Z")

</div>

I am getting this error on windows machine.  
‘REACT\_APP\_STAGE’ is not recognized as an internal or external command,  
Cant find any related solution.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [April 6, 2019, 10:46pm UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/6 "2019-04-06T22:46:00Z")

</div>

I think this has to do with the command line format. I don’t know the windows version too well. But if you can figure out how to run this on your machine, you should be good.

```auto
$ REACT_APP_TEST_VAR=123 npm start

```

---

<div class="post-metadata">

**Author:** ![derektumulak](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/derektumulak/32/497_2.png) [@derektumulak](https://discourse.sst.dev/u/derektumulak)\
**Post date:** [May 12, 2019, 2:41am UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/7 "2019-05-12T02:41:43Z")

</div>

I believe I’m running into the same problem on Windows. Were you able to find a solution?

Thanks!  
-Derek

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 27, 2019, 12:14am UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/8 "2019-05-27T00:14:36Z")

</div>

I’m not super familiar with how to set things for Windows. Hopefully somebody can help out.

---

<div class="post-metadata">

**Author:** ![derektumulak](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/derektumulak/32/497_2.png) [@derektumulak](https://discourse.sst.dev/u/derektumulak)\
**Post date:** [May 27, 2019, 12:48am UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/9 "2019-05-27T00:48:55Z")

</div>

I was able to get it working using cross-env. I had to install the package and use the syntax below:

“start”: “cross-env REACT\_APP\_STAGE=dev react-scripts start”,  
“build”: “react-scripts build”,  
“test”: “react-scripts test --env=jsdom”,  
“predeploy”: “cross-env REACT\_APP\_STAGE=dev npm run build”,

Thanks!

-Derek

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [June 17, 2019, 5:36pm UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/10 "2019-06-17T17:36:47Z")

</div>

Is this for Windows?

---

<div class="post-metadata">

**Author:** ![taqtical](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@taqtical](https://discourse.sst.dev/u/taqtical)\
**Post date:** [March 2, 2020, 4:38pm UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/11 "2020-03-02T16:38:17Z")

</div>

If you’re in Windows, you should change command to “set REACT\_APP\_STAGE=xxx && npm…”

---

<div class="post-metadata">

**Author:** ![taqtical](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@taqtical](https://discourse.sst.dev/u/taqtical)\
**Post date:** [March 2, 2020, 4:42pm UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/12 "2020-03-02T16:42:32Z")

</div>

Hi. I deployed the app in dev and prod environments in AWS S3. Everything OK, until I found that the production app is using dev resources (Cognito, database, etc). Anyone can tell me how to set the REACT\_APP\_STAGE variable in the S3 bucket?

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [March 8, 2020, 8:39pm UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/13 "2020-03-08T20:39:57Z")

</div>

So the environments are set while building the app. So the `REACT_APP_STAGE=prod npm run build` is setting it.

---

<div class="post-metadata">

**Author:** ![taqtical](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@taqtical](https://discourse.sst.dev/u/taqtical)\
**Post date:** [March 18, 2020, 3:56am UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/14 "2020-03-18T03:56:12Z")

</div>

I finally solved it having two versions of the .env file (.env.dev and .env.prod) and copy the environment file to .env when deploying to each one.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [March 30, 2020, 10:54pm UTC](https://discourse.sst.dev/t/environments-in-create-react-app/30/15 "2020-03-30T22:54:57Z")

</div>

I see. Yeah that works.
