当我在不使用npm start
的情况下运行vs代码调试器时,它似乎托管了我的应用,因为我可以在Chrome中浏览它而不运行npm start
。我的应用程序在端口3000上,我的调试器在端口5858上。今天早些时候没有这个问题。运行我的angular universal app时,我得到this error,然后运行我的调试器来调试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...
答案 0 :(得分:0)
似乎你有两个应用程序在同一个端口上运行,没有1.e 3000.
使用此命令
netstat -tulpn
显示服务器上的所有进程,然后将kill
与进程ID一起使用。与kill processid
一样。