Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng serve Port 4200 is already in use #15369

Closed
a-korzhov opened this issue Aug 18, 2019 · 10 comments
Closed

ng serve Port 4200 is already in use #15369

a-korzhov opened this issue Aug 18, 2019 · 10 comments

Comments

@a-korzhov
Copy link

a-korzhov commented Aug 18, 2019

馃悶 Bug report

Command (mark with an x)

ng serve --open --port XXXX says error:
Port XXXX is already in use. Use '--port' to specify a different port.
in cmd "netstats" that ports are not used.

Description

Using Intellij Idea.
Its just simple AngularCLI application without additional code.
Just starting npm install -g @angular/cli@1.7.4
and ng new angularclient
Trying to make application Spring Boot + Angular - https://www.baeldung.com/spring-boot-angular-web

After i tried to make another Angular project without backend, just used WebStorm -> AngularCLI -> node v10.16.3. I have got the same error

馃敟 Exception or Error




> frontend@0.0.0 start C:\Users\korzh\Programming\Java\Study\Spring\FullStack\frontend
> ng serve

Port 4200 is already in use. Use '--port' to specify a different port.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend@0.0.0 start: `ng serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the frontend@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\korzh\AppData\Roaming\npm-cache\_logs\2019-08-18T18_40_28_465Z-debug.log

my project structure first time(when i Did Angular and Spring in 1 project).
-angularclient: e2e, node_modules, src, angular-clie.json, other files...
-src: main->java, resources->static, templates, application.properties; test
pom.xml

When i did it in Intellij in Spring project, my .angular-cli-json -> "$schema": "./node_modules/@angular/cli/lib/config/schema.json", was saying "node_modules not found",
deleted "./", alt+enter on node_modules and its creating package in src/main/resources/static/node_modules. When i tried to move all my angularclient project to "static" - not working.

If it securaly i can share what is in C:\Users\korzh\AppData\Roaming\npm-cache_logs\2019-08-18T18_40_28_465Z-debug.log
Anything else relevant?

@michalstepien
Copy link

It is bug in portfinder

@michalstepien
Copy link

@angular\cli\utilities check-port.js

@a-korzhov
Copy link
Author

a-korzhov commented Aug 19, 2019

Did you try killing the port??

did you reac that i have no potrs to kill?
I`ve cloned hello world project from github (dont remember which one), and it works.
There was 7.2.0 versions in package.json dependencies, in my project was 5.x.x versions. Could it be reason of error?

@michalstepien
Copy link

@korzh17 do you have webpack-dev-server in package.json?

@michalstepien
Copy link

I've added to my packege.json portfinder": "~1.0.20" and change package-lock.json portfinder to ,
"portfinder": {
"version": "1.0.20",
"resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.20.tgz",
"integrity": "sha512-Yxe4mTyDzTd59PZJY4ojZR8F+E5e97iq2ZOHPz3HDgSvYC5siNad2tLooQ5y5QHyQhc3xVqvyk/eNA3wuoa7Sw==",
"requires": {
"async": "^1.5.2",
"debug": "^2.2.0",
"mkdirp": "0.5.x"
}
},

and works

@hoacodai000
Copy link

hoacodai000 commented Aug 19, 2019

Reason: node-portfinder > v1.0.21.
Fix: in package.json
add => "portfinder": "1.0.20"
"dependencies": {
"@angular/animations": "~8.2.0",
"@angular/common": "~8.2.0",
"@angular/compiler": "~8.2.0",
"@angular/core": "~8.2.0",
"@angular/forms": "~8.2.0",
"@angular/http": "~7.2.15",
"@angular/platform-browser": "~8.2.0",
"@angular/platform-browser-dynamic": "~8.2.0",
"@angular/router": "~8.2.0",
"core-js": "^3.1.4",
"rxjs": "~6.5.2",
"zone.js": "~0.10.1",
"portfinder": "1.0.20"
}

@clydin
Copy link
Member

clydin commented Aug 19, 2019

Version 1.7.4 is no longer supported. Please update to a newer version (8.2.2 is the latest stable version). If the problem persists please file a new issue.

@clydin clydin closed this as completed Aug 19, 2019
@a-korzhov
Copy link
Author

thanks

@jebali-f
Copy link

I had the same problem, all ports are refused.
Here are the steps to fix it:

  • add portfinder in the devDependencies block
    "devDependencies": {
    "portfinder": "1.0.20",
    }
  • Remove node_modules
  • clear the cache
  • run npm install

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants