typescript - VSC 调试在 WSL 上运行的 Node.js Typescript
问题描述
我正在尝试调试使用 Typescript 编写的、在 WSL 上运行的 Node.js 应用程序。
环境是:
- 操作系统:Windows 10
- 调试工具:VSC 1.24.1 / VSC 1.25 / VSC 1.26.0
- WSL:Ubuntu 18.04
- 应用:Typescript Node.js,代码来自https://github.com/Microsoft/TypeScript-Node-Starter
我的 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”。
第一次尝试可能会错过它(我知道这听起来很奇怪),但再次重新加载。当您设置断点时,它可能会抱怨说“未验证...”或“尚未绑定”。但是,当代码运行时,它将被验证。
调试生活愉快!
解决方案
推荐阅读
- java - 如何允许多个外部域从单个应用程序访问数据?
- swiftui - SwiftUI http 请求
- python-3.x - 如何使用递归函数在给定列表中找到最小值
- flutter - Dismissible 和 FutureBuilder 不能一起工作
- php - 将多个图像上传到 Laravel 5.8 选择,并在发送到服务器之前具体删除
- java - 如果 Google Cloud Pub/Sub 在 30 秒内未收到响应,则会重试消息传递。故意的?
- java - java按钮java中的空指针异常错误
- mysql - 我可以在 MySQL 中获取 json 列的唯一/不同值吗?
- multithreading - 如何在 C++ 中定义两个类之间的公共互斥锁
- c# - 如何使用 ASP .NET MVC 打开、编辑和保存存储在服务器中的 word 文件