0

When ever I try to launch my react app, it doesn't matter what port I am running on, it always says the port is in use.

? Something is already running on port 12345. Would you like to run the app on another port instead? › (Y/n)

Currently using a .env file to set the port: PORT=12345

node version: v14.17.0 npm version: v7.21.1 OS: CentOS 8

How can I force it to use the port I list, currently I'm forced to have a dynamic port, which is really hindering me for a static url mapping.

Aidan
  • 757
  • 3
  • 13
  • What is the output of netstat -ltnp | grep -w ':12345' you could do kill all to force kill – Ramakay Aug 30 '21 at 00:46
  • I don't get any outputs from that command, if i remove grep, this is all i get. – Aidan Aug 30 '21 at 02:00
  • 127.0.0.1:42961 0.0.0.0:22 0.0.0.0:8089 192.168.1.16:2368 0.0.0.0:36801 0.0.0.0:43597 0.0.0.0:111 :::80 :::22 :::443 :::36539 :::9090 :::43143 :::111 – Aidan Aug 30 '21 at 02:01
  • It doesn't seem to matter which port number I try, react always thinks its in use – Aidan Aug 30 '21 at 02:02
  • in your env file are you listing it as PORT = 12345 or REACT_APP_PORT = 12345 – Dan Aug 30 '21 at 03:21
  • PORT=12345 Which is obviously working, as thats the port that it says its trying to load on. But even with out this port, standard 3000 is not working, and theres nothing running on it – Aidan Aug 30 '21 at 04:36
  • I added the .env file, after experiencing this problem, and after file introduction, problem persists – Aidan Aug 30 '21 at 04:37
  • https://unix.stackexchange.com/questions/106561/finding-the-pid-of-the-process-using-a-specific-port - See here, you still need to find out who is the running process to troubleshoot. – Ramakay Aug 30 '21 at 13:36
  • Thats just it, nothing is running on these ports, i can pick ANY port, and REACT thinks that it is in use, even if its not. – Aidan Aug 30 '21 at 14:19

1 Answers1

0

for create react apps you need to include REACT_APP in your .env file try it as REACT_APP_PORT = 12345

checkout the accepted answer here: create react app not picking up .env files?

Dan
  • 361
  • 1
  • 5
  • 17
  • This does not work, I believe the correct format is PORT=12345 Using REACT_APP_PORT=12345 , seems to be unrecognised by React and defaults to trying to use 3000, which causes the same issue – Aidan Aug 30 '21 at 06:09
  • By unrecognized do you mean undefined? If you console.log your REACT_APP_PORT var what does it show? – Dan Aug 30 '21 at 13:25
  • If I use PORT=12345 , then to npm start , then it tries to start on port 12345, if I do REACT_APP_PORT=12345, then it tries to start on 3000, so PORT= is obviously the correct option. – Aidan Aug 30 '21 at 14:17