VSCode NodeJs:调试器无法在断点处停止(WSL2/Ubuntu18)

3

使用WSL2 / Ubuntu18,我无法让VSCode NodeJs调试器在任何NodeJs应用程序的断点处停止。当我启动调试器时,它会运行(我可以在集成终端上看到输出),但是断点被简单地忽略了。

simple.js文件,在第3行上有一个断点:

Simple JS with Breakpoint at line 3

launch.json设置如下:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "NodeJs: Launch Program",
            "program": "${file}",
            "request": "launch",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "type": "pwa-node",
            "console": "integratedTerminal"
        }
    ]
}

当我按下F5或在VS Code上点击“开始调试”按钮时,应用程序会运行,并且以下内容将显示在集成终端中:
/usr/bin/env 'NODE_OPTIONS=--require /home/myuser/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/extensions/ms-vscode.js-debug/src/bootloader.bundle.js --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"/tmp/node-cdp.19338-1.sock","deferredMode":false,"waitForDebugger":"","execPath":"/home/myuser/.nvm/versions/node/v14.15.1/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/tmp/node-debug-callback-ff32d873905abafa"}' /home/myuser/.nvm/versions/node/v14.15.1/bin/node ./simple.js 
Debugger attached.
0
1
2
3
4
Waiting for the debugger to disconnect...

我已经从Node10升级到Node14,但问题仍然存在。

在另一台使用WSL1的计算机上,使用相同的launch.json文件,调试器会停在指定的断点处。我是否还需要在WSL2上设置其他内容?记录一下,在WSL1计算机上,在停在第3行之前,集成终端上会显示以下内容:

/usr/bin/env 'NODE_OPTIONS=--require /home/myuser/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/extensions/ms-vscode.js-debug/src/bootloader.bundle.js --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"/tmp/node-cdp.787-3.sock","deferredMode":false,"waitForDebugger":"","execPath":"/home/myuser/.nvm/versions/node/v14.15.1/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/tmp/node-debug-callback-b901b6d6e3e9799b"}' /home/myuser/.nvm/versions/node/v14.15.1/bin/node ./simple.js 
Debugger attached.
<Breakpoint hit and stop...>

Debugger stops at breakpoint

附加信息,调试 Python3 文件在两台机器上都能正常工作。

两台电脑都安装了相同的 VS Code 版本。

更新:

您可以在 GitHub 上关注此问题:https://github.com/microsoft/vscode/issues/113283

2个回答

1
问题在于NodeJs应用程序是从符号链接的地址运行的,因此调试器无法处理它。
来自VSCode/NodeJS开发人员在github上的回答:
“看起来你将脚本链接到了/bin/nhosko/simple.js,但它的实际位置是/mnt/c/Users//bin-nhosko/simple.js。在这种情况下,您需要指定一些标志,以便Node报告vscode看到并告诉调试器的链接位置: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_can-i-debug-if-im-using-symlinks。我希望调试器能够自动解决这个问题,在microsoft/vscode-js-debug#776中。”

https://github.com/microsoft/vscode/issues/113283#issuecomment-750371948


0
在 Visual Studio Code 中,我在 JavaScript 调试终端遇到了这个问题。
--inspect-publish-uid= is not allowed in NODE_OPTIONS

我把Visual Studio Code移动到了应用程序文件夹,结果运行正常了。之前它在下载文件夹里。

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