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

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

问题描述

我有一个拒绝运行的 Angular 应用程序.它一直说 端口 1234 已在使用中.使用--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 上打开,而如果我尝试使用 3000 或任何其他带有 Angular 的端口号,它就会失败.所以这不是端口被其他进程使用的问题.

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

推荐答案

看起来是这样的 portfinder 的问题.我能够通过在 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 serve 拒绝使用任何端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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