我遇到了同样的问题,正如在这个答案中解决的那样:Unable to debug Typescript in VSCode
不幸的是,这对我来说似乎不起作用。任何帮助表示赞赏。
我的文件夹结构:
这是我的tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
//"declaration": true,
"inlineSourceMap": false,
"lib": [
"es6"
],
"outDir": "./dist",
"moduleResolution": "node",
"sourceMap": true,
"mapRoot": "./maps"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
这是我的launch.json:
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/src/index.ts",
"cwd": "${workspaceRoot}",
"outFiles": [
"${workspaceRoot}/dist/**/*.js"
]
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}",
"outFiles": [
"${workspaceRoot}/dist/**/*.js"
]
}
]
}
答案 0 :(得分:0)
终于找到了答案......
问题不在launch.json或tsconfig.json中。这就是我生成源地图的方式。编译器总是显示:
error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'.
但是在tsconfig.json中配置了sourceMap选项。 我查看了gulp-typescript的文档,并尝试了在那里生成sourceMaps的“集成”解决方案。所以它现在看起来像这样:
gulp.task('compile', () => {
let tsResults = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject());
return tsResults.js
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('dist'));
});
之前,有一个单独的任务来生成源地图。我想这有一个问题:
gulp.task('sourcemaps', () => {
gulp.src('dist/**/*.js')
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('dist'));
});