Is it possible to debug workers? Every time I try, I get:
Starting inspector on 127.0.0.1:49344 failed: address already in use
Error: child process exit with code 12: connection problem
As soon as worker is created.
I use VS Code and launch.json looks like:
{
"type": "node",
"request": "launch",
"name": "Debug gdmn-back",
"cwd": "${workspaceRoot}/src/gdmn-back",
"program": "${workspaceRoot}/src/gdmn-back/src/index.ts",
"outFiles": [
"${workspaceRoot}/src/gdmn-back/dist/src/**/*.js"
],
"console": "externalTerminal",
"internalConsoleOptions": "openOnSessionStart",
"autoAttachChildProcesses": true
},
I think, if it is NOT POSSIBLE at all, it should be printed with bold letters at the start of corresponding chapter of Nodejs docs. So, there will be no need to spend days searching internet for a solution which doesn't exist.
If there is a way, then it would be good to add it to official docs. As both nodejs and vscode web sites don't say a word about the topic.
I love Nodejs, but inability to debug workers code makes me mad ((
@gsbelarus Are you talking about worker_threads workers or cluster workers?
If it鈥檚 worker_threads workers, Chrome DevTools doesn鈥檛 support them yet but e.g. https://github.com/GoogleChromeLabs/ndb/ and some IDEs do.
If it鈥檚 cluster workers, yes, that is possible. If necessary, you can manually specify a port using inspectPort: https://nodejs.org/api/cluster.html#cluster_cluster_settings
We use worker_threads. I will evaluate ndb. Thanks for the link!
Seems it works for me:
yarn global add ndbcd to project folderyarn rebuildndb node ./dist/src/index.js (path will depend on project!)ndb ., browse to sources and put break point, then follow #5.
Most helpful comment
Seems it works for me:
yarn global add ndbcdto project folderyarn rebuildndb node ./dist/src/index.js(path will depend on project!)ndb ., browse to sources and put break point, then follow #5.