【问题标题】:Port 4200 is already in use. Use '--port' to specify a different port端口 4200 已在使用中。使用“--port”指定不同的端口
【发布时间】:2021-04-18 23:35:19
【问题描述】:

尝试运行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! product@0.0.0 start: `ng serve --host 0.0.0.0 --disable-host-check`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the product@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\Mohammad Ajo\AppData\Roaming\npm-cache\_logs\2019-08-18T18_19_41_366Z-debug.log

我已经检查了端口是否被另一个连接保留,并尝试多次更改端口,但始终收到相同的错误。

【问题讨论】:

  • 关闭 vscode 并重新打开它,10 美元你正在运行多个终端
  • lsof -i :4200 找到并杀死它(连姆尼森风格)
  • 我在 Windows 10 上使用 intelliJ。即使重新启动我的计算机,错误仍然出现。
  • 进入资源监视器(可以在开始菜单中搜索),打开network选项卡,查看哪个进程在使用4200端口和end processstackoverflow.com/questions/48198/…

标签: npm angular-cli


【解决方案1】:

对于 Linux 用户:- 这个对我有用

kill -9 $(lsof -t -i:4200)

【讨论】:

    【解决方案2】:

    几个小时前我也遇到了同样的问题。尝试检查: https://github.com/angular/angular-cli/issues/15369

    在我的情况下安装 portfinder@1.0.21 有效。

    【讨论】:

    • 非常感谢。将 "portfinder": "1.0.20" 添加到我的 package.json 后,该问题已得到解决。
    【解决方案3】:

    要使用 angular 连接 asp.net web api 项目,我已将端口 4200 分配给它。如果您不这样做,您可以使用 ng serve --port 4600 就像另一个对我有用的端口一样。

    【讨论】:

      【解决方案4】:

      尝试运行ng serve --port 4500 或更改package.json 而不是

      "start": "ng serve",

      输入

      "start": "ng serve --port 4500",

      然后运行npm start 命令

      【讨论】:

      • 我已经尝试了多次,但都遇到了同样的错误。
      【解决方案5】:

      运行以下命令,---o 将自动打开不同端口的新窗口:

      ng serve ---o --port=0 // will open on random port automatically
      

      如果你想要特定的端口然后运行:

      ng serve ---o --port 4201 // Will open on port 4201
      

      【讨论】:

        猜你喜欢
        • 2017-11-12
        • 2021-02-17
        • 1970-01-01
        • 2019-11-01
        • 2019-12-24
        • 2016-12-29
        • 2018-08-20
        • 2017-01-13
        • 2023-04-06
        相关资源
        最近更新 更多