Visual Studio 节点:调试到工作线程(节点 11) [英] Visual Studio Node: debug into Worker Threads (node 11)

查看:24
本文介绍了Visual Studio 节点:调试到工作线程(节点 11)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS Code 的 Javascript 调试器可以用来调试节点 11 的新工作线程"吗?工作线程以 Web 工作线程为模型,顶部有少量额外功能,可从新的 worker_threads 包中获得(参见

不幸的是,工作线程没有.当工作线程运行时,调试器不会显示它,并且不允许您放置断点或单步执行代码.我怀疑这可能是因为:https://github.com/nodejs/node/issues/26609

VS 代码

VSC 没有调试工作线程的功能.有趣的是,VCS 也没有调试 Web Workers 的功能.这是他们的明确决定:https://github.com/Microsoft/vscode-chrome-debug/issues/675

Can VS Code's Javascript debugger be made to debug node 11's new "Worker Threads"? Worker threads are modelled after web workers with a small number of extra capabilities on top and are available from the new worker_threads package (see https://nodejs.org/api/worker_threads.html). Other than with node's sub processes, one can share memory with worker threads in the form of SharedArrayBuffers.

My VS Code launch configuration looks like that:

   {
        "type": "node",
        "request": "launch",
        "name": "Mocha Tests",
        "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
        "runtimeArgs": [
            "--experimental-wasm-threads",
            "--experimental-worker"
        ],
        "args": [
            "-u", "tdd",
            "--timeout", "100000",
            "--colors", "${workspaceFolder}/test"
        ],
        "internalConsoleOptions": "openOnSessionStart",
        "autoAttachChildProcesses": true
   }

I can debug into the main node script, but the "autoAttachChildProcesses" flag is not effective in attaching to the spawned off worker threads and neither is adding a "debugger" statement within the code that runs inside the worker thread.

They mention that the "inspector" package is not yet supported for worker threads in their reference documentation, so I guess this may explain why that is.

Against all these odds, has anyone still succeeded in debugging into worker threads inside VS Code?

解决方案

UPDATE Feb 2021 It is now possible to debug worker threads in VSC using vscode-js-debug as pointed out in the other answer. I have tested it and it works quite well. Webstorm remains a great alternative, with perhaps a bit more features built-in, but bear in mind that it is a paid product.

Disclaimer: The answer below describes my experience debugging worker threads, but not using VS Code, which was the original question. I thought it would be useful to know alternative options anyway, since it seems that as of today the only option to debug worker threads is Webstorm.

Webstorm option

It is possible to debug worker threads using Webstorm: https://blog.jetbrains.com/webstorm/2018/10/webstorm-2018-3-eap-6/ I have tried it and it works really well (as documented in the link above).

Chrome tools

I have tried debugging worker threads using chrome dev tools, following the same approach in which you would debug web workers, but it did not work. When debugging web workers, they show up like this in chrome tools

Unfortunately, worker threads do not. When a worker thread runs, the debugger does not show it, and does not let you put breakpoints nor step through the code. I suspect that this may be because of this: https://github.com/nodejs/node/issues/26609

VS Code

VSC does not have a feature to debug worker threads. Interestingly, VCS also does not have a feature to debug Web Workers. This is an explicit decision on their part: https://github.com/Microsoft/vscode-chrome-debug/issues/675

这篇关于Visual Studio 节点:调试到工作线程(节点 11)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆