Debugging VS Code with Typescript shows transpiled variable names instead of real names

十年热恋 提交于 2020-12-31 15:22:03

问题


I'm struggling to find the right configuration such that VS Code will show me the real variable name for debugging.

In the attached image, I should be able to see the conn (for example) variable but the debugger is showing the transpiled version exports.conn.

//tsconfig.json
{
    "compilerOptions": {
        "baseUrl": ".",
        "target":"es6",
        "module":"commonjs",
        "noImplicitAny": false,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "outDir": "dist",
        "moduleResolution": "node",
        "allowJs": false,
        "allowSyntheticDefaultImports": false,
        "esModuleInterop": false,
        "jsx": "react"
    },
    "include": [
        "web/**/*",
        "logger/**/*",
        "controller/**/*",
        "config/**/*",
        "**/*.ts"

    ]
}
// VS Code launch.json
      ...
               {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/app.ts",
            "console": "integratedTerminal",
            "outFiles": ["${workspaceFolder}/dist/**/*"]
        }

UPDATE: I'm not convinced this is a VS Code problem. If I run the app from a terminal with node dist/app and get a stack trace it doesn't point back to the original TS files but rather the compiled JS files.

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at new Config (/Users/zzz/Documents/programming/dist/config/Config.js:10:56)
    at Object.<anonymous> (/Users/zzz/Documents/programming/dist/config/Config.js:43:18)

UPDATE 2: I fixed the CLI problem by moving require('source-map-support').install(); to be my very first import. Now the CLI output does show the correct line/stack trace back through the the .ts files but the same problem still exists in VS Code.

来源:https://stackoverflow.com/questions/56669155/debugging-vs-code-with-typescript-shows-transpiled-variable-names-instead-of-rea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!