簡體   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