这是我的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"
        },

我的源文件夹:

debugging - 无法在VSCode中调试Typescript-LMLPHP

我的dist文件夹:

debugging - 无法在VSCode中调试Typescript-LMLPHP

我得到的错误是:
Cannot launch program '/Dev/myapp/server/src/app.ts'; setting the 'outFiles' attribute might help.

如果我将“program”属性更改为“” program“:” $ {workspaceRoot}/dist/server/src/app.js“,它可以工作,但是我正在调试已编译的javascript,而不是 typescript 。 .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"
  ]
}

最佳答案

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

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

还要将mapRoot中的tsconfig.json设置为./dist/。目前,它将在./server/src文件夹中搜索源 map ,而不是./dist

关于debugging - 无法在VSCode中调试Typescript,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42747618/

10-13 07:33