I need to run my ReactJS application on the port 1234
but when I run yarn dev
, I get the following:
$ parcel src/index.html --port 1234
Server running at http://localhost:2493 - configured port 1234 could not be used.
√ Built in 11.45s.
It doesn't tell me why it can't run on port 1234
, so I suspected that the port might be in use already. According to this answer, the following should tell me what process is using that port.
Get-Process -Id (Get-NetTCPConnection -LocalPort portNumber).OwningProcess
But that didn't help, it gave the following message:
Get-NetTCPConnection : No MSFT_NetTCPConnection objects found with property 'LocalPort' equal to '1234'. Verify the value of the property and retry.
Which I guess means there is no process bound to port 1234
. But if that is the case, why can't I bind to that port?
My package.json
is as follows:
{
"name": "bejebeje.react",
"version": "1.0.0",
"description": "bejebeje's react-js frontend",
"main": "index.js",
"repository": "[email protected]:JwanKhalaf/Bejebeje.React.git",
"author": "John",
"license": "GPL-3.0",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.19",
"@fortawesome/free-brands-svg-icons": "^5.9.0",
"@fortawesome/free-solid-svg-icons": "^5.9.0",
"@fortawesome/pro-light-svg-icons": "^5.9.0",
"@fortawesome/pro-regular-svg-icons": "^5.9.0",
"@fortawesome/pro-solid-svg-icons": "^5.9.0",
"@fortawesome/react-fontawesome": "^0.1.4",
"@reach/router": "^1.2.1",
"oidc-client": "^1.8.2",
"react": ">=16",
"react-dom": "^0.14.9 || ^15.3.0 || ^16.0.0-rc || ^16.0",
"react-icons": "^3.7.0",
"styled-components": "^4.3.2"
},
"scripts": {
"dev": "parcel src/index.html --port 1234",
"build": "parcel build src/index.html"
},
"devDependencies": {
"@fortawesome/fontawesome-pro": "^5.9.0",
"axios": "^0.19.0",
"parcel-bundler": "^1.12.3",
"prettier": "^1.16.4",
"sass": "^1.22.5"
}
}
After creating a little C# web server that would attempt to bind to the port 1234
I still couldn't get it to work. It would try to bind, but would throw an exception saying:
An attempt was made to access a socket in a way forbidden by its access permissions.
Anyways, after much pain and research here is what finally worked:
First, disable hyper-v (this will restart your PC, so ensure all work is saved). In PowerShell (as admin) run the following:
dism.exe /Online /Disable-Feature:Microsoft-Hyper-V
When your PC has restarted, you need to reserve the port you want so hyper-v doesn't reserve it back, again via PowerShell as admin, run the following:
netsh int ipv4 add excludedportrange protocol=tcp startport=50051 numberofports=1
Now finally re-enable hyper-V (PC will restart again), again via PowerShell as admin:
dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All
when your PC has finished and is back up, you should be able to bind to that port successfully.
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