首页 文章

无法在VSCode中调试Typescript

提问于
浏览
4

这是我的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.

如果我将“program”属性更改为“”program“:”$ /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 回答

  • 5

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

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

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

  • 0

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

    "program": "${file}"
    

    显然在尝试在节点中运行ts文件时,在将其更改为时按F5 / Ctrl F5

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

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

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

相关问题