2

I am trying to install a React Web Application on my Windows system. It was working fine earlier but when I re-installed my Windows then it stopped working. I have already installed Node and Npm.

When I run the command npm install it goes well. But when I run the command npm start it throws the following error:

REACT_APP_ENV is not recognized as an internal or external command

Please see the attached image also:

enter image description here

I have tried a lot to find and fix the issue but nothing worked.

Here is package.json file content:

{
  "name": "wm-webapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "gapi-client": "0.0.3",
    "libphonenumber-js": "^1.7.7",
    "moment": "^2.24.0",
    "node-sass": "^4.11.0",
    "react": "^16.7.0",
    "react-bootstrap": "^0.32.4",
    "react-dates": "^18.4.1",
    "react-dom": "^16.7.0",
    "react-facebook-login": "^4.1.1",
    "react-google-login": "^5.0.0",
    "react-places-autocomplete": "^7.2.0",
    "react-redux": "^5.0.7",
    "react-responsive": "^6.1.1",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-router-redux": "^5.0.0-alpha.9",
    "react-scripts": "2.1.3",
    "react-select": "^1.2.1",
    "react-stripe-elements": "^2.0.2",
    "react-table": "^6.8.6",
    "react-toastify": "^4.5.2",
    "redux": "^4.0.1",
    "redux-devtools-extension": "^2.13.7",
    "redux-form": "^8.1.0",
    "redux-form-input-masks": "^1.3.0",
    "redux-logger": "^3.0.6",
    "redux-saga": "^1.0.0",
    "redux-thunk": "^2.3.0",
    "store": "^2.0.12",
    "styled-components": "^4.1.3"
  },
  "scripts": {
    "start:env": "env-cmd .env.${REACT_APP_ENV} react-scripts start",
    "start": "REACT_APP_ENV=dev npm run start:env",
    "start:test": "REACT_APP_ENV=test npm run start:env",
    "build:env": "env-cmd .env.${REACT_APP_ENV} react-scripts build",
    "build": "REACT_APP_ENV=test npm run build:env",
    "build:prod": "REACT_APP_ENV=prod npm run build:env",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "deploy": "aws s3 cp build s3://test.washmix.com/ --recursive --profile washmix",
    "format": "prettier --write --single-quote --tab-width=2 --print-width=80"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "axios-mock-adapter": "^1.16.0",
    "env-cmd": "^8.0.2",
    "husky": "^1.3.1",
    "prettier": "^1.16.1"
  }
}
10
  • can you share you package.json file as well? Commented Feb 21, 2019 at 15:03
  • is this a create-react-app ? Commented Feb 21, 2019 at 15:04
  • Try running set REACT_APP_ENV=dev in the command prompt before running npm start. Commented Feb 21, 2019 at 15:05
  • seems like a duplicate issue stackoverflow.com/questions/9249830/… Commented Feb 21, 2019 at 15:05
  • @AkashdeepSingh tired, still showing same error Commented Feb 21, 2019 at 15:14

4 Answers 4

10

Already late to answer but for people searching for the answer..

For Windows (cmd.exe) :

'set "REACT_APP_ENV=dev" && npm run start'

For Windows (Powershell) :

'($env:REACT_APP_ENV = "dev") -and (npm start)'

For Linux, macOS (Bash) :

'REACT_APP_ENV=dev npm start'

You can anytime get thing variable with process.env.REACT_APP_ENV

Sign up to request clarification or add additional context in comments.

Comments

8

You must change all environment variables in your package.json for:

Set NAME_VARIABLE=VALUE 

Ex:

"start": "Set REACT_APP_ENV=dev&& npm run start:env",

Comments

1

If you're running on windows, remember to leave no space between the commands and &&.
So the start script will be :

"start-staging":"set REACT_APP_ENV=staging&&react-scripts start"

1 Comment

Not necessary with the tests I ran through. e.g. "build:qa": "Set REACT_APP_ENV=qa && npm run build"
0

In script-> start, write cross-env in starting of the value. After that Run: npm install.

And you are ready to go

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.