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
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
# 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With