简体   繁体   中英

VSCode attach debug to nodejs which run on WSL

I get error: Cannot connect to runtime process, timeout after 10000ms - (reason: cannot connect to the target)

NodeJs v4.3.1 run on WSL.

The below is my launch.json

"type": "node",
"request": "attach",
"name": "Attach to WSL",
"port": 3000,
"address": "localhost",
"restart": true,
"protocol": "inspector",
"localRoot": "${workspaceFolder}/web-frontend",
"remoteRoot": "/mnt/c/workspace/.../web-frontend"

WSL uses the path from Windows so localRoot and remoteRoot are the same.

What am I missing so far?

I created a VS Code extension: WSL workspaceFolder , which will help you to automatically set the remoteRoot in your launch.json to the correct WSL path. For example my launch.json , based upon your file paths would look like below;

/vscode/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": "attach", "name": "Attach to Remote", "address": "localhost", "port": 5858, "localRoot": "${workspaceFolder}/web-frontend", "remoteRoot": "${command:extension.vscode-wsl-workspaceFolder}/web-frontend" } ] }

Then to start a debug session, in the WSL terminal enter NODE_ENV=debug node --nolazy --inspect-brk=5858 before the path to the script you wish to debug.

However, you may run into problems using Node v4 because it does not support the 'inspector protocol'. I would strongly recommend you upgrade to a more recent version of Node. Currently v8 is the latest LTS version: Node.js releases

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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