VS Code 调试器停止后不会杀死 Node 进程

6
我正在使用express.js作为Web框架,监听端口3000,开发一款基于node.js的应用程序。 我使用的是VS Code v1.46。 我的launch.json文件如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "program": "${workspaceFolder}\\WebApi\\index.js",
        "restart": true,
        "protocol": "inspector"
    }
   ]
  }

我能够开始第一次的调试会话,但是在第二次及以后,我会得到错误 Error: listen EADDRINUSE: address already in use :::3000

这个错误是由于VSCode没有终止在第一次调试会话中创建的node.exe进程,所以在后续会话中,由于端口3000仍在使用中,node无法启动express服务器。

有谁可以帮助我配置VSCode,在停止调试器后终止node.exe进程?

2个回答

3
这个问题在上周才开始发生,我不确定是什么原因,可能是 Windows 更新了。无论如何,我找到了以下解决方法: https://github.com/OmniSharp/omnisharp-vscode/issues/2387 他们说如果你在launch.json中添加以下代码 "console": "externalTerminal" 或者 "console": 'integratedTerminal',将会为该进程打开一个控制台,以便你手动终止它。

0

使用“预览”调试扩展可以正常工作。

这是使用该模式的launch.json,只需确保您放置了您的package.json的正确命令即可。

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node-terminal",
      "name": "Run Script: start",
      "request": "launch",
      "command": "npm run start",
      "cwd": "${workspaceFolder}"
    }
  ]
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接