【问题标题】:Running VS Code debugger seems to host my web app运行 VS Code 调试器似乎托管了我的 Web 应用程序
【发布时间】:2017-05-05 07:57:43
【问题描述】:

当我只运行 vs 代码调试器而不使用 npm start 时,它似乎托管了我的应用程序,因为我可以在 Chrome 中浏览到它,甚至无需运行 npm start。我的应用程序在端口 3000 上,我的调试器在端口 5858 上。今天早些时候没有这个问题。我在运行我的 Angular 通用应用程序然后运行我的调试器来调试 node.js 后端时得到this error,因为两个进程正在尝试使用相同的端口。这意味着我无法使用 GUI 触发我的后端功能,因此很难测试后端。为什么调试我的应用程序似乎托管它?

这是我的 launch.json 文件:

{
    "version": "0.2.0",
    "configurations": [{
        "name": "Launch",
        "type": "node2",
        "request": "launch",
        "program": "${workspaceRoot}/src/server.ts",
        "stopOnEntry": false,
        "skipFiles": [
            "node_modules/**/*.js"
        ],
        "args": [],
        "cwd": "${workspaceRoot}",
        "preLaunchTask": null,
        "runtimeExecutable": null,
        "runtimeArgs": [
            "--nolazy"
        ],
        "env": {
            "NODE_ENV": "development"
        },
        "externalConsole": false,
        "sourceMaps": true,
        "outFiles": ["${workspaceRoot}/dist/**/*.js"],
        "address": "localhost",
        "port": 5858
    }, {
        "name": "Attach",
        "type": "node2",
        "request": "attach",
        "port": 5858,
        "address": "localhost",
        "restart": false,
        "sourceMaps": false,
        "outDir": null,
        "localRoot": "${workspaceRoot}",
        "remoteRoot": null
    }, {
        "name": "Attach to Process",
        "type": "node2",
        "request": "attach",
        "processId": "${command.PickProcess}",
        "port": 5858,
        "sourceMaps": false,
        "outDir": null
    }]
}

这是我不使用npm start 托管我的应用程序时的调试控制台:

node --inspect=5858 --debug-brk --nolazy dist/server/index.js 
Debugger listening on port 5858.
Warning: This is an experimental feature and could change at any time.
Debugger attached.
slimy sam
slimy sam
Listening on: http://localhost:3000

这是我已经使用npm start 托管我的应用程序时的调试控制台:

node --inspect=5858 --debug-brk --nolazy dist/server/index.js 
Debugger listening on port 5858.
Warning: This is an experimental feature and could change at any time.
Debugger attached.
slimy sam
events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: listen EADDRINUSE :::3000
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at Server._listen2 (net.js:1257:14)
    at listen (net.js:1293:10)
    at Server.listen (net.js:1389:5)
    at EventEmitter.listen (/private/var/root/vepo/node_modules/express/lib/application.js:617:24)
    at Object.<anonymous> (/private/var/root/vepo/dist/server/index.js:57532:18)
    at Object.<anonymous> (/private/var/root/vepo/dist/server/index.js:57537:30)
    at __webpack_require__ (/private/var/root/vepo/dist/server/index.js:27:30)
    at /private/var/root/vepo/dist/server/index.js:93:18
Waiting for the debugger to disconnect...

编辑:当我在 launch.json 中将其设置为 false 时,它​​还会在进入时停止调试器,因此我的 vs 代码可能刚刚损坏。我可能需要重新安装它,尽管我试图避免它,因为我有很多扩展。

当我将应用程序运行的端口更改为 4000 时,我在调试时遇到相同的错误,但为 4000:

events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: listen EADDRINUSE :::4000
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at Server._listen2 (net.js:1257:14)
    at listen (net.js:1293:10)
    at Server.listen (net.js:1389:5)
    at EventEmitter.listen (/private/var/root/vepo/node_modules/express/lib/application.js:617:24)
    at Object.<anonymous> (/private/var/root/vepo/dist/server/index.js:57532:18)
    at Object.<anonymous> (/private/var/root/vepo/dist/server/index.js:57537:30)
    at __webpack_require__ (/private/var/root/vepo/dist/server/index.js:27:30)
    at /private/var/root/vepo/dist/server/index.js:93:18
Waiting for the debugger to disconnect...

【问题讨论】:

  • 看起来npm start 正在端口 3000 上启动服务器,并且您的调试器配置也在端口 3000 上启动服务器。我不明白仅使用调试器启动的问题 - 什么npm start 还可以吗?

标签: node.js angular visual-studio-code angular-universal


【解决方案1】:

您似乎有两个应用程序在同一个端口号 1.e 3000 上运行。

使用这个命令

netstat -tulpn

显示服务器上的所有进程,然后使用 kill 和进程 id 。喜欢kill processid

【讨论】:

  • 你能告诉我当你在终端输入这个命令'netstat -tulpn'时它显示什么
  • 我通过lsof -n -i4TCP:3000 得到它显示所有使用端口 3000 的进程。它只是显示调试器运行端口 3000,因为它不会使用该端口,然后我启动调试器并且某些东西正在使用该端口。关于你的回答,上面写着sh-3.2# netstat -tulpn netstat: n: unknown or uninstrumented protocol sh-3.2#
  • 如果您发现任何与端口 3000 相关的进程,则终止或停止该进程。我认为在那之后它会起作用。
  • 你能做点什么吗,试着改变你的应用程序的端口号。
  • 是的,我刚刚发布了我的问题底部发生的事情。干杯
猜你喜欢
  • 2022-10-14
  • 2017-02-05
  • 2019-04-07
  • 1970-01-01
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多