ng服务拒绝使用任何端口 [英] ng serve refuses to use any port

查看:93
本文介绍了ng服务拒绝使用任何端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个拒绝运行的Angular应用程序.它一直说Port 1234 is already in use. Use '--port' to specify a different port.,这很废话,因为它说的是我抛出的任何端口号.我知道这些端口没有使用,因为我没有使用它们.如果我运行live-server之类的东西,它可以在端口3000上正常运行.我将其关闭并告诉ng serve使用端口3000,它的行为就好像端口3000在使用中.

I have an Angular application that refuses to run. It keeps saying Port 1234 is already in use. Use '--port' to specify a different port., which is crap because it says that about any port number I throw in. I know these ports aren't in use because I'm not using them. If I run something like live-server, it runs fine on port 3000. I shut it down and tell ng serve to use port 3000, it then acts like port 3000 is in use.

我重新启动了Macbook,尝试了lsof -t -i tcp:80 -s tcp:listen | sudo xargs kill之类的命令,但没有任何帮助.

I've rebooted my macbook, I've tried commands like lsof -t -i tcp:80 -s tcp:listen | sudo xargs kill and nothing has been any help.

我在另一个目录中有一个不同的Angular应用程序,当我运行ng serve时,它可以正常工作,但同样,该应用程序目前不在运行,并且不应该阻止正在尝试使用的该特定应用程序.

I have a different Angular App in another directory that works fine when I run ng serve but again, that one's not running at the moment and shouldn't be blocking this particular app I'm trying to work on.

我访问过";端口4200已在使用中".当运行ng serve命令时,似乎没有一个解决方案起作用.

I've visited "Port 4200 is already in use" when running the ng serve command and none of the solutions there seemed to have worked.

我敢肯定,除了保留端口,目前没有其他端口在使用中.如果我打开我的React项目之一并运行npm run start,它将很高兴地在端口3000上打开,而如果我尝试使用Angular的3000或任何其他端口号,它将失败.因此,这不是其他进程正在使用端口的问题.

I'm pretty sure there aren't any ports other than the reserved ones in use at the moment. If I open one of my React projects and run npm run start it happily opens up on port 3000, whereas if I try 3000, or any other port number with Angular, it fails. So it's not an issue of ports being in use by other processes.

这是Angular CLI 6.1.10

This is Angular CLI 6.1.10

推荐答案

看起来像是端口查找器问题.通过在我的package.json的devDependencies中显式声明portfinder的版本,我能够使它工作.

Looks like this is an issue with portfinder. I was able to get it working by explicitly declaring the version of portfinder in my devDependencies of my package.json.

"devDependencies": {
    "@angular-devkit/build-angular": "~0.7.0",
    "@angular/cli": "6.1.3",
    "portfinder": "1.0.20",
}

这篇关于ng服务拒绝使用任何端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆