【发布时间】:2017-08-30 06:09:17
【问题描述】:
VSCode 版本:1.10.2 操作系统版本:Windows 7 专业版,SP1 节点版本:6.10.0
大家好。
当使用 nodemon 启动它时,我正在尝试使用 Visual Studio 代码在服务器端调试打字稿代码(或 javascript 代码)。我在 launch.json 中添加了一个新配置,如下所示:
{
"type": "node",
"request": "launch",
"name": "Launch server with Nodemon",
"runtimeExecutable": "nodemon",
"runtimeArgs": [
"--debug=5858"
],
"program": "${workspaceRoot}/src/server.ts",
"restart": true,
"port": 5858,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": ["${workspaceRoot}/build/**/*.js"]
}
我在运行 tsc 的 vscode 中有一个任务,它可以正确构建 javascript 文件。这是我当前的任务配置:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
}
当我更改打字稿文件时,会按预期生成 javascript 文件。 生成 javascript 文件时,nodejs 服务器正在按预期重新启动。
但我无法在任何断点上中断(在打字稿文件或 javascript 文件上)。
你能告诉我这是一个问题还是我遗漏了什么?
感谢您的帮助
【问题讨论】:
-
为了调试,我通常只在我的控制台上写这个: node --inspect --debug-brk my-file.js 抓住链接,把它粘贴到我的浏览器上就可以了。
-
声明
debugger也被忽略。在没有 nodemon 的情况下启动时,program(在 launch.js 中)必须设置为 typescript 文件,并且outFiles必须指定到生成的 javascript 文件的映射。但是使用nodemon启动时如何做到这一点? -
@ManfredSteiner:您可以在下面看到我的答案...也许它会回答您的问题。但是在简历中,在您的 tsconfig.json 中,您必须将“outDir”选项设置为路径你想在哪里输出你的 js 文件(例如:“outDir”:“./build”)。然后,在您的 launch.json 中,将“outFiles”选项设置为与之前设置的路径相同的路径,但您必须使用 blob 正则表达式来选择它们(请参阅下面的配置)。此外,在您的 launch.json 中将“sourceMaps”选项设置为 true。希望对你有帮助
-
@TiagoBértolo:我不确定这是在 vscode IDE 中调试 typescript/javascript 代码的正确方法。这个想法是在 Visual Studio 代码中进行调试并在编辑器文件中到达断点。我不明白您的解决方案如何解决我的问题。但无论如何,如果您需要在 vscode 中调试和中断断点,您可以在下面看到我的答案。
-
@Philoufelin 我告诉你用 Chrome 开发工具调试你的应用程序,而不用 vscode。
标签: node.js typescript visual-studio-code breakpoints nodemon