【问题标题】:VS Code Debugger does not kill node process after stopping the debugger停止调试器后 VS Code 调试器不会终止节点进程
【发布时间】:2020-06-26 07:10:52
【问题描述】:

我正在开发一个 node.js 应用程序,使用 express.js 作为 Web 框架在 PORT 3000 上侦听。 我正在使用 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"
    }
   ]
  }

我第一次可以启动调试会话,但第二次以后,我收到错误 错误:监听 EADDRINUSE:地址已在使用 :::3000

此错误是因为 VSCode 没有终止在第一个调试会话中创建的 node.exe 进程,因此在随后的会话中,节点无法在端口 3000 上启动 express 服务器,因为它仍在使用中。

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

【问题讨论】:

    标签: node.js visual-studio-code vscode-debugger


    【解决方案1】:

    这个问题上周才开始对我来说,不知道为什么,也许是 Windows 更新。

    我发现以下任何方式: https://github.com/OmniSharp/omnisharp-vscode/issues/2387

    如果您添加到lunch.json,他们会说 "console": "externalTerminal""console": 'integratedTerminal'

    它将为进程打开一个控制台,以便您可以手动终止

    【讨论】:

      【解决方案2】:

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

      这是使用该模式的launch.json,只要确保你输入了正确的package.json命令。

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

      【讨论】:

        猜你喜欢
        • 2019-11-09
        • 2019-03-19
        • 2019-04-11
        • 2019-06-09
        • 2019-05-14
        • 1970-01-01
        • 2023-03-12
        • 1970-01-01
        • 2015-06-30
        相关资源
        最近更新 更多