VSCode在typescript中设置断点

时间:2017-11-21 03:32:08

标签: javascript typescript

我想使用vscode调试typescript,我试图在我的typescript源文件中设置断点。这是我的launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${file}",
            "outFiles": [
                "${workspaceRoot}/dist/**/*.js"
            ],
            "cwd": "${workspaceRoot}",
            "sourceMaps": true,
            "console": "integratedTerminal"
        }
    ]
}

我使用gulp观看打字稿并将其编译为.js。这是tsconfig.json

{
    "files": [
        "src/**/*.ts"
    ],
    "compilerOptions": {
        "module": "commonjs",
        "removeComments": true,
        "allowJs": true,
        "target": "es2015",
        "sourceMap": true,
        "types": [
            "node",
            "lodash"
        ]
    },
    "exclude": [
        "node_modules"
    ]
}

但是当我在typescript文件中设置断点时,会出现错误:cannt launch the program src/xxx.ts because corresponding JavaScript cannot be found.我已检查gulp已将.ts编译为dist/

1 个答案:

答案 0 :(得分:0)

而不是

"outFiles": [
    "${workspaceRoot}/dist/**/*.js"
],

你应该使用

"outDir": "${workspaceRoot}/dist"