angular-cli: ng serve --open reports port 4200 is already in use when it isn't
ng serve --open incorrectly reports that port 4200 is in use, even when no browsers are open.
Versions
Angular CLI: 1.6.7
Node: 8.9.4
OS: win32 x64
Angular: 5.2.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.6.7
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.7
@schematics/angular: 0.1.17
typescript: 2.5.3
webpack: 3.10.0
Repro steps
- ng new aatest1 -si
- cd aatest1
- npm install
- ng serve --open
Observed behavior
ps>ng serve --open
Port 4200 is already in use. Use '--port' to specify a different port.
Desired behavior
ng serve --open should work correctly
Mention any other details that might be useful (optional)
The above behavior did NOT occur with Angular-CLI 1.6.6 or earlier.
Work-around
specify --port 4216 (any value between 4200 and 4215 causes the above mentioned error)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 18 (1 by maintainers)
fuser -n tcp -k 4200 ng serve
I have attached the output from netstat. I cannot find anything that is listening on ports 4200 through 4215, the ones that no longer work as of Angular-CLI 1.6.7.
It’s as if the parsing of the default port number’s last two digits (00) is messed up because specifying port 4216 or above seems to work.
If I specify port 4201, for example, I still get the same error (port 4201 is in use):
Only ports 4216 and above work for me. Example:
aatest.txt
If you are receiving that error, something on your system is listening on that port. If on Windows, you can use
netstat -abno
to find which process is listening on the port(s) in question.I confirm that the error is present in Windows from version 1.6.7 and later. It occurs every time the application build stops due to some errors. Evidently in case of an error the used door is not closed. What instead happens correctly until version 1.6.6
Until this issue is resolved, Windows users can run the following PowerShell script that will find and kill the process that is still using Port 4200:
Example output when port 4200 is being used:
Example output when port 4200 is not being used:
Ubuntu ( terminal command ) kill -9 $(lsof -i tcp:4200 -t)
On a mac: netstat -anv | grep 4200
@gmarab : correct. It is still happening to me with Angular-CLI 1.7.0.
I have to “fight the tool” (Angular-CLI in this case) by constantly changing the
--port
value if an error occurs and I have to start the process up again:It’s annoying and I hope this gets fixed soon.