繁体   English   中英

无法在Visual Studio Code中调试TypeScript

[英]Cant debug TypeScript in Visual Studio Code

我遇到了同样的问题,此答案已解决: 无法在VSCode中调试Typescript

不幸的是,这似乎不适用于我。 任何帮助表示赞赏。

我的文件夹结构:

文件夹结构

这是我的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"
            ]
        }
    ]
}

终于偶然找到答案了...

问题不在launch.json或tsconfig.json中。 这就是我生成源地图的方式。 编译器始终显示:

error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'.

但是sourceMap选项是在tsconfig.json中配置的。 我查看了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'));
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM