有没有人得到Node.js调试器才能使用带有源代码目录结构的typescript源图?

时间:2016-04-20 17:17:51

标签: node.js typescript visual-studio-code

我正在尝试找到一个目录配置和一组构建/启动选项,这些选项将使VSCode调试器能够让我设置断点并通过不在源树根目录中的TypeScript文件进行调试。

例如,采用简单的Express应用程序:

(root)
|
+ app.ts
+ app.js
+ app.js.map
|
+ routes/
    |
    + index.ts
    + index.js
    + index.js.map

当我在调试器下的VSCode中运行它时,在启动配置中将sourceMaps设置为true,我可以在app.ts中设置断点,但不能在index.ts中设置断点。

有没有人能够这样设置断点并通过非根目录中的打字稿文件进行调试? TIA

1 个答案:

答案 0 :(得分:0)

由于你还没有发布你的launch.json,我会在这里粘贴一个适用于我的版本,并允许使用大量嵌套文件夹来回调试nodejs应用程序:

"configurations": [
    {
        // Name of configuration; appears in the launch configuration drop down menu.
        "name": "Launch Server",
        // Type of configuration.
        "type": "node",
        // Workspace relative or absolute path to the program.
        "program": "${workspaceRoot}/server/app.ts",
        // Automatically stop program after launch.
        "stopOnEntry": false,
        // Command line arguments passed to the program.
        "args": [],
        // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
        "cwd": "${workspaceRoot}",
        // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
        "runtimeExecutable": null,
        // Optional arguments passed to the runtime executable.
        "runtimeArgs": ["--nolazy", "--harmony", "--harmony_default_parameters"],
        // Environment variables passed to the program.
        "env": {
            "NODE_ENV": "development"
        },
        // Use JavaScript source maps (if they exist).
        "sourceMaps": true,
        // If JavaScript source maps are enabled, the generated code is expected in this directory.
        "outDir": "${workspaceRoot}/dist/dev",
        "request": "launch"
    }]

此处的兴趣点为:programsourceMapsoutDir。确保它们都设置正确。

您也可以查看地图的外观(我认为它们很好,因为您可以调试根文件)。但是以下是js.map,其中一个文件嵌套在根目录下的文件夹中(server是根文件夹):

{"version":3,"sources":["server/middleware/Server.ts"],......,"sourceRoot":"/Users/someuser/projects/myproject"}

希望这有帮助。