简体   繁体   中英

Set env in windows command line/ package.json

Am having issues running a react app on windows .

The app was initially setup to run on a macOS .
Below are the error messages and package.json file.

Question : How can I start and build PORT for windows?

package.json

{
  "name": "tradingview-finnhub",
  "private": true,
  "dependencies": {
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.4.0",
    "request-promise": "^4.2.5"
  },
  "scripts": {
    "start": "PORT=8080 react-scripts start",
    "build": "PORT=8080 react-scripts build"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Error message

'PORT' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! tradingview-finnhub@ start: `PORT=8080 react-scripts start`
npm ERR! Exit status 1

You just need to add set before the PORT=8080 and a & after it.

It would be something like:

"scripts": {
    "start": "set PORT=8080 & react-scripts start",
    "build": "set PORT=8080 & react-scripts build"
  },

The problem is that you need to set the environment variable of PORT before running the react-script, the solution I gave does that. For more info you can see:

https://superuser.com/questions/79612/setting-and-getting-windows-environment-variables-from-the-command-prompt

How do I run two commands in one line in Windows CMD?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM