0

当我只运行 vs 代码调试器而不使用npm start时,它似乎托管了我的应用程序,因为我可以在 Chrome 中浏览到它而无需运行npm start。我的应用程序在端口 3000 上,我的调试器在端口 5858 上。今天早些时候没有这个问题。我在运行我的 Angular 通用应用程序然后运行我的调试器来调试 node.js 后端时收到此错误,因为两个进程正在尝试使用相同的端口。这意味着我无法使用 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...
4

1 回答 1

0

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

使用此命令

netstat -tulpn

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

于 2016-12-20T07:14:39.117 回答