无法在VSCode中调试Typescript [英] Unable to debug Typescript in VSCode
问题描述
这是我的launch.json
Here is my 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"
},
我的源文件夹:
我的dist文件夹:
我得到的错误是:
Cannot launch program '/Dev/myapp/server/src/app.ts'; setting the 'outFiles' attribute might help.
如果我将 program属性更改为 program: $ {workspaceRoot} / dist /server/src/app.js,它可以工作,但是我随后在调试已转译的javascript而不是打字稿。显然,使用.map文件进行转译是有效的,这是怎么回事?
If I change the "program" property to ""program": "${workspaceRoot}/dist/server/src/app.js", it works but I'm then debugging the transpiled javascript and not the typescript. Obviously the transpiling with .map files is working, what is wrong?
tsconfig.json
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
文件夹:
You are missing src
folder in your configuration:
"outFiles": [
"${workspaceRoot}/dist/server/src/*.js"
],
还要将 tsconfig.json
中的 mapRoot
设置为 ./ dist /
。当前它将在您的 ./ server / src
文件夹中搜索源地图,而不是 ./ dist
Also set your mapRoot
in tsconfig.json
to ./dist/
. Currently it will search your ./server/src
folder for sourcemaps instead of ./dist
这篇关于无法在VSCode中调试Typescript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!