简体   繁体   English

等待调试器断开连接... - VSCode 中的 Node.js

[英]Waiting for debugger to disconnect... - Node.js in VSCode

I'm trying to step through a simple javascript example in Visual Studio Code, but the debugger hangs trying to disconnect.我正在尝试逐步执行 Visual Studio Code 中的一个简单的 javascript 示例,但调试器在尝试断开连接时挂起。

macOS Sierra version 10.12.6 macOS Sierra 版本 10.12.6

VSCode version 1.18.1 (up to date) VSCode 版本 1.18.1(最新)

Node.js v8.9.2 (up to date) installed with Homebrew Node.js v8.9.2(最新)与 Homebrew 一起安装

Debugging with inspector protocol because Node.js v8.9.2 was detected.
node --inspect-brk= /*(port)*/ jsSandbox.js 
Debugger listening on ws:// (ip address)
Debugger attached.
Waiting for the debugger to disconnect...

This seems like it's been a closed issue with both Code and Node already, which is why I'm so confused.这似乎已经是CodeNode的一个已解决问题,这就是我如此困惑的原因。 Am I doing something wrong?难道我做错了什么?

Here is the only javascript file I'm trying to debug:这是我尝试调试的唯一 javascript 文件:

// learning about closure

function increase() {  // — gets called once
    var getBig = 0;
    return function() {  // — — gets called each time 
        getBig += 1;      // — — increments each time
        console.log(getBig);
    };
}
var bigOne = increase(); // --  a reference to the instance of the function
bigOne(); //1
bigOne();//2 

...and the project's launch.json config: ...和项目的 launch.json 配置:

        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/jsSandbox.js",
            "console": "internalConsole"
        }

click on the button as shown below to open launch.json-点击下图按钮打开launch.json-

打开 Launch.json

Give your correct file name here, where your server is starting.在此处输入正确的文件名,即您的服务器启动的位置。 In my case it is app.js就我而言,它是 app.js

"version": "0.2.0",
"configurations": [
    {
        "type": "node",
        "runtimeVersion": "10.21.0", 
        "request": "launch",
        "name": "Launch Program",
        "program": "${workspaceFolder}/app.js"
    }
]

runtimeVersion is optional, its required if you want to run it on a specific node version.And that node version should be installed on your system. runtimeVersion 是可选的,如果你想在特定的节点版本上运行它,它是必需的。并且该节点版本应该安装在你的系统上。

I found a syntax error in my code.我在我的代码中发现了一个语法错误。 The problem was that I wasn't catching the exception.问题是我没有捕捉到异常。 Using VS Code, I just ticked "Uncaught Exceptions" and found the faulty code.使用 VS Code,我只是勾选了“未捕获的异常”并找到了错误的代码。

You should make sure the tab showing problems is empty, ie, you should address all problems.您应该确保显示problems的选项卡是空的,即您应该解决所有问题。 In cases where the problems are from the files in node_modules , the problems go away just by closing those windows.如果问题来自node_modules的文件,只需关闭这些窗口,问题就会消失。

For example in the following pictures, there are 4 issues in Problems tab.例如在下图中, Problems选项卡中有 4 个问题。 Fixing them will make the debugger to work correctly!修复它们将使调试器正常工作!

在此处输入图片说明

Use $'{file} for active window:使用 $'{file} 作为活动窗口:

{

  "version": "0.2.0",
  "configurations": [{
    "type": "node",
    "request": "launch",
    "name": "Active window",
    "program": "${file}"
  }]
}

For me a dependency crashed while debugging, which seems to also crash the vscode debugger itself.对我来说,调试时依赖项崩溃了,这似乎也会使 vscode 调试器本身崩溃。 Restarting VSCode would allow me to debug again.重新启动 VSCode 将允许我再次调试。 Removing the faulty dependency (ie fixing the code, as suggested in the other answer), allows the debugging process to close, although the Debug Console message still was confusing:删除错误的依赖项(即修复代码,如另一个答案中所建议的那样),允许调试过程关闭,尽管调试控制台消息仍然令人困惑:

Debugger listening on ws://127.0.0.1:48673/54esaf46-659e-sd92-5e45-01e78845825e
Debugger attached.
Waiting for the debugger to disconnect...

It would appear the debugger can't disconnect.看起来调试器无法断开连接。 But I have no trouble starting a new debug session afterwards.但是我之后开始新的调试会话没有问题。

Check your launch.json file.检查您的 launch.json 文件。 Its present in folder .vscode in your project.它存在于项目中的文件夹 .vscode 中。 In launch.json change program value to ${workspaceFolder}/.在 launch.json 中,将程序值更改为 ${workspaceFolder}/。

For me what helped was the following:对我来说有帮助的是以下内容:

  1. created another new debugger anywhere in the program.在程序的任何地方创建了另一个新的调试器。
  2. Run the new debugger运行新的调试器
  3. Stop the new debugger from the play/stop/step menu从播放/停止/步骤菜单停止新的调试器

It kind of resets the debugger I think from this "can't disconnect" glitch.我认为从这个“无法断开连接”的故障中重置调试器。

I found multiple "Node Debug" extensions installed.我发现安装了多个“节点调试”扩展。 "React Native Tools" had a dependency on both of these. “React Native Tools”依赖于这两者。 After I removed the "React Native Tools" and then the "Node Debug" extensions, VS Code resumed normal and expected behavior of running the debugger.在我删除“React Native Tools”和“Node Debug”扩展之后,VS Code 恢复了运行调试器的正常和预期行为。 I used the default launch configuration:我使用了默认的启动配置:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/bin/www"
        }
    ]
}

It happens when you break your code.当您破坏代码时会发生这种情况。 Start your project and you'll see that your app is crashing.启动你的项目,你会看到你的应用程序崩溃了。 Fix the problem and you'll be able to debug again.修复问题,您将能够再次调试。

你可以检查 .json { "type": "node", "request": "launch", "name": "程序", "program": "${workspaceFolder}/ main.js " }

This happened for me when I added wrong file path in protractor.conf.js specs[].当我在 protractor.conf.js specs[] 中添加错误的文件路径时,这发生在我身上。 I forgot to add file extension.我忘了添加文件扩展名。

I found I had the Chrome Debugger tools open in another tab, that was the one that was holding it up.我发现我在另一个选项卡中打开了 Chrome 调试器工具,这就是阻止它的那个。 Just close that one.关闭那个就行了。

I opened the Task Manager and stopped this process:我打开任务管理器并停止了这个过程:

qemu-system- X86_64.exe (4)

See example见例子

请先检查您的代码,编译您的代码时应该会出现一些问题。

I'm trying to step through a simple javascript example in Visual Studio Code, but the debugger hangs trying to disconnect.我试图通过Visual Studio Code中的一个简单的javascript示例,但是调试器挂起并试图断开连接。

macOS Sierra version 10.12.6 macOS Sierra版本10.12.6

VSCode version 1.18.1 (up to date) VSCode版本1.18.1(最新)

Node.js v8.9.2 (up to date) installed with Homebrew随Homebrew一起安装的Node.js v8.9.2(最新)

Debugging with inspector protocol because Node.js v8.9.2 was detected.
node --inspect-brk= /*(port)*/ jsSandbox.js 
Debugger listening on ws:// (ip address)
Debugger attached.
Waiting for the debugger to disconnect...

This seems like it's been a closed issue with both Code and Node already, which is why I'm so confused.看来这已经是CodeNode的一个封闭问题,这就是为什么我如此困惑。 Am I doing something wrong?难道我做错了什么?

Here is the only javascript file I'm trying to debug:这是我要调试的唯一javascript文件:

// learning about closure

function increase() {  // — gets called once
    var getBig = 0;
    return function() {  // — — gets called each time 
        getBig += 1;      // — — increments each time
        console.log(getBig);
    };
}
var bigOne = increase(); // --  a reference to the instance of the function
bigOne(); //1
bigOne();//2 

...and the project's launch.json config: ...以及项目的launch.json配置:

        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/jsSandbox.js",
            "console": "internalConsole"
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM