Angular-cli: ng serve claims port is in use when it isn't.

Created on 19 Aug 2019  路  3Comments  路  Source: angular/angular-cli

馃悶 Bug report

Command (mark with an x)

- [ ] new
- [ ] build
- [x ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

Unsure

Description

Despite the fact that it's given a free port, ng serve refuses to run on any port, saying "Port XXXX is already in use. Use '--port' to specify a different port." where XXXX is the port number. It's not an issue of the port being in use by another process, because I used the same port number to launch other applications, like React, and those worked fine. It is rejecting any port number I give it with the same error.

I have two angular applications, one works fine, the other does not. Both are in the same directory, but should not be interfering with each other

Directory tree:

udemyangular
--my-first-app
--prnnppr-app

First one won't run, second one does. my-first-app is nothing more than the scaffold from ng new, and prnnppr-app is just a starter project for work with a few custom components, I have otherwise not touched .angular.json, or package.json or any of the other config files. I've also deleted and regenerated my-first-app and got the same result.

馃敩 Minimal Reproduction

Create two angular applications in the same directory, run ng serve in both of them. Theoretically they should both run fine (provided of course they're given different ports.)

馃敟 Exception or Error


Port 3000 is already in use. Use '--port' to specify a different port.

馃實 Your Environment


OS: darwin x64
Angular: 6.1.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cli                      6.0.8
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.5.2
typescript                        2.7.2
webpack                           4.8.3

Anything else relevant?
Other programs, like npm run start for React, run just fine on any given port number, so it's not an issue of the ports being in use by some other process.

Commands like sudo kill $(sudo lsof -t -i:4200) have not helped.

Rebooting the pc did not help.

Most helpful comment

@jckuhl : this appears to be an issue with the portfinder package (as seen here in #15369).

To fix it, I explicitly downgraded my portfinder by adding "portfinder": "1.0.20" to my devDependencies block (local dev only) in my package.json.

After deleting node_modules, and doing an npm install, all works as intended again (until this is fixed in portfinder).

(Note: I see that the linked stackoverflow solution does the exact same thing)

All 3 comments

@jckuhl : this appears to be an issue with the portfinder package (as seen here in #15369).

To fix it, I explicitly downgraded my portfinder by adding "portfinder": "1.0.20" to my devDependencies block (local dev only) in my package.json.

After deleting node_modules, and doing an npm install, all works as intended again (until this is fixed in portfinder).

(Note: I see that the linked stackoverflow solution does the exact same thing)

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hartjo picture hartjo  路  3Comments

sysmat picture sysmat  路  3Comments

gotschmarcel picture gotschmarcel  路  3Comments

naveedahmed1 picture naveedahmed1  路  3Comments

NCC1701M picture NCC1701M  路  3Comments