无法在VSCode中调试Typescript

时间:2017-03-12 12:51:03

标签: debugging typescript visual-studio-code

这是我的launch.json

    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "name": "Launch Server",
            "request": "launch",
            "program": "${workspaceRoot}/server/src/app.ts",
            "cwd": "${workspaceRoot}",
            "env": {
                "NODE_ENV": "dev"
            },
            "skipFiles": [
                "node_modules/**/*.js"
            ],
            "outFiles": [
                "${workspaceRoot}/dist/server/src/*.js"
            ],
            "sourceMaps": true,
            "stopOnEntry": true,
            "console": "internalConsole"
        },

我的源文件夹:

enter image description here

我的dist文件夹:

enter image description here

我得到的错误是:

Cannot launch program '/Dev/myapp/server/src/app.ts'; setting the 'outFiles' attribute might help.

如果我更改"程序"属性""程序":" $ {workspaceRoot} /dist/server/src/app.js" ;,它可以正常工作,但我会调试已编译的javascript而不是打字稿。显然,使用.map文件进行转换是有效的,出了什么问题?

tsconfig.json

{
  "compilerOptions": {
    "allowJs": false,
    "baseUrl": "",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es6",
      "dom"
    ],
    "mapRoot": "./",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "./dist",
    "sourceMap": true,
    "target": "es6",
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "exclude": [
    "web",
    "dist",
    "node_modules"
  ]
}

2 个答案:

答案 0 :(得分:5)

您的配置中缺少src文件夹:

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

同时将mapRoot中的tsconfig.json设置为./dist/。目前,它会在您的./server/src文件夹中搜索源图,而不是./dist

答案 1 :(得分:0)

在我的情况下,我在launch.json

"program": "${file}"

当点击 F5 / Ctrl + F5 时,显然试图在节点中运行ts文件 将其更改为

"program": "${workspaceFolder}/${fileBasenameNoExtension}.js"

允许我运行活动的ts和js文件......

还启动tsc -watch构建任务以获取动态编译的js文件