问题
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