首页 > 解决方案 > VSC 调试在 WSL 上运行的 Node.js Typescript

问题描述

我正在尝试调试使用 Typescript 编写的、在 WSL 上运行的 Node.js 应用程序。

环境是:

我的 launch.json 是:

{
"version": "0.2.0",
"configurations": [        

    {
        "type": "node",
        "request": "launch",
        "name": "Launch via NPM",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
            "run-script",
            "debug"
        ],
        "port": 9229,
        "useWSL": true,
        "console": "externalTerminal",
        "timeout": 100000,
        "restart": true,
        "sourceMaps": true
    }
]

}

当我按 F5 时,它不会在 Debug 断点处停止并说“未找到 bened code”。但是当我查看 dist 文件夹时,它有 *.map 文件。

你能帮我弄清楚吗?

有没有办法远程调试在 WSL 上运行的 Typescript node.js 应用程序?我找不到解决方案。

提前致谢!

- 更新 -

VSC 1.25 有一个关于远程调试的错误,请尝试 1.24.1 或 1.26

相反,我发现了如何附加它并且调试器工作。launch.json 需要以下内容:

        {
        "type": "node",
        "request": "attach",
        "name": "Attach WSL",
        "port": 9229,
        "sourceMaps": true,
        "localRoot": "${workspaceFolder}",
        "remoteRoot": "/mnt/c/prj/tmp/TypeScript-Node-Starter",
        "outFiles": [
            "${workspaceFolder}/dist/**/*.js"
        ]
    },

要进行测试,请在 home.ts:8 处设置断点,然后从您的浏览器加载“localhost:3000”。

第一次尝试可能会错过它(我知道这听起来很奇怪),但再次重新加载。当您设置断点时,它可能会抱怨说“未验证...”或“尚未绑定”。但是,当代码运行时,它将被验证。

调试生活愉快!

标签: typescriptvisual-studio-codewindows-subsystem-for-linux

解决方案


推荐阅读