【问题标题】:Property outFiles is not allowed in vs code's launch.jsonVS 代码的 launch.json 中不允许使用属性 outFiles
【发布时间】:2020-10-10 04:51:17
【问题描述】:

我正在尝试在 vs 代码中调试打字稿。据我研究,您需要在 thlaunch.config 中为 vs 代码设置 outfiles 属性,以映射您在已编译的 .js 文件中在 TypeScript 文件中设置的断点,指定为 here

当我尝试设置我的时,我得到了这个错误:

我在 google 中没有发现有关此错误的任何信息,因为打字稿调试器需要此设置才能工作,如 vs code documentation 中所示。

提前感谢您的帮助。

编辑:

launch.json:

"configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome",
            "url": "http://localhost:3000",
            "webRoot": "${workspaceFolder}",
            "preLaunchTask": "tsc",
            "sourceMaps": true
        }
    ]

tsconfig:

{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    /* Basic Options */
    // "incremental": true,                   /* Enable incremental compilation */
    "target": "es5",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "strict": true,                           /* Enable all strict type-checking options. */
    "esModuleInterop": true,                  /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    "inlineSourceMap": true,               /* Emit a single file with source maps instead of having a separate file. */
    "inlineSources": true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

    /* Advanced Options */
    "skipLibCheck": true,                     /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
    "outDir": "src/ts-built",
    "rootDir": "src"
  }
}

【问题讨论】:

    标签: typescript vscode-settings vscode-debugger


    【解决方案1】:

    您不能将"outFiles" : true 用于 chrome 调试配置

    如果您希望调试您的 typescript 代码,您需要确保您已将 ts 编译器设置为生成源映射。

    确保您的tsconfig 文件中有这两个设置。

    //TSCONFIG SETTINGS
    "inlineSourceMap": true /* Emit a single file with source maps instead of having a separate file. */,
    "inlineSources": true /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */,
    

    如果您的tsconfig 中已经有"sourceMap": true,,如果您想使用"inlineSourceMap": true NOT FROM LAUNCH.JSON,则需要将其删除!

    这些设置将为您的代码生成内联源映射。

    最后你的 launch.config 应该是这样的

    {
      "name": "Launch Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000",
      "webRoot": "${workspaceRoot}/wwwroot",
      "sourceMaps": true // this is is the important setting. 
    }
    

    【讨论】:

    • 非常感谢您的回答。我按照您的指示进行操作,但如果我在 .js 中设置断点,它会在那里中断,但不是在 .ts 中,这正是我想要的。我在问题中更新了我的 tsconfig 和 launch.json
    • 很抱歉,让我检查一次
    • 嘿,我检查了一个演示项目,在这里,它似乎在这里工作i.imgur.com/Vq5HvLg.gifv这里是文件gofile.io/d/5dtpy1如果你想交叉检查
    • 如果还是不行,能否提供更多关于项目类型、文件夹结构和使用脚本的 html 文件的详细信息?
    • 欢迎您!我在手机上,但我想帮忙
    猜你喜欢
    • 2020-10-01
    • 2018-12-03
    • 2021-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 1970-01-01
    • 2020-03-01
    相关资源
    最近更新 更多