3

I'm trying to change the default port being used by create react app. If I use "start": "PORT=4000 react-scripts start" and restart the server, it works fine. But using "start": "process.env.REACT_APP_PORT react-scripts start" returns undefined. My .env.development file has REACT_APP_PORT=4000 and I can console log the port from index.js, so it does seem to be set OK at that point

1 Answers1

5

process.env.PORT will start the app on the desired port (current CRA version is 1.1.4 at the time of this response)

Hence in your env file

.env

# Works
  PORT=4000
# Won't Work
  REACT_APP_PORT=4000

This is because PORT is used by webpack (in CRA) at build time and not by React at run time.

A list of variables NOT requiring the REACT_APP prefix can be found here

Community
  • 1
  • 1
Verric
  • 1,044
  • 3
  • 11
  • 19