0

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
MwamiTovi
  • 2,425
  • 17
  • 25
Jason Maynard
  • 359
  • 1
  • 3
  • 15
  • Use something like https://www.npmjs.com/package/cross-env – jonrsharpe Aug 13 '20 at 16:12
  • 1
    Does this answer your question? [How can I set NODE\_ENV=production on Windows?](https://stackoverflow.com/questions/9249830/how-can-i-set-node-env-production-on-windows) – jonrsharpe Aug 13 '20 at 16:13
  • 1
    Simply remove the part `PORT=8080` from those scripts, that should work (at least, if it was set up with `create-react-app`). Once it runs, then you could get back and declare `PORT=3000`. Starting with either approach should give us insight... – MwamiTovi Aug 13 '20 at 16:35
  • This worked perfect – Jason Maynard Aug 13 '20 at 18:18

1 Answers1

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?

Juan Casian
  • 346
  • 3
  • 9
  • Worked like a charm, I was also able to get it to work by removing `PORT=8080` all together and just running `react-script-build`. Thank you for the info! – Jason Maynard Aug 14 '20 at 13:30