使用 outFile 引用正确打字稿文件的浏览器错误消息

Browser error messages referencing correct typescript file using outFile

我正在使用 tsconfig.json 中的 outFile 选项将我的打字稿文件编译成一个 .js 文件。
我正在生成源地图。
不过,错误消息 引用打字稿文件。

示例:


script.ts: throw 'Error'
tsconfig.json:

{
  "compilerOptions": {
    "sourceMap": true
  }
}

编译(tsc 1.6.2)将生成:
script.js: throw 'Error
script.js.地图:{"version":3,"file":"script.js","sourceRoot":"","sources":["script.ts"],"names":[],"mappings":"AACA,MAAM,QAAQ,CAAC"}

浏览器的控制台(Chrome 47.0.2526.73 m)会显示:Uncaught Error. script.ts:1

很好。


script.ts: throw 'Error'
tsconfig.json:

{
  "compilerOptions": {
    "sourceMap": true,
    "outFile": "app.js"
  }
}

编译(tsc 1.6.2)将生成:
app.js: throw 'Error
app.js.地图:{"version":3,"file":"app.js","sourceRoot":"","sources":["script.ts"],"names":[],"mappings":"AACA,MAAM,QAAQ,CAAC"}

浏览器的控制台(Chrome 47.0.2526.73 m)会显示:Uncaught Error. app.js:1

app.js应该是app.ts

如何让浏览器将错误消息引用到我的打字稿文件中?

我用过相同版本的Chrome浏览器。然而ts编译器版本是1.7.3

开发工具控制台已打开。

1 个案例:

  • ts.config

    { "compilerOptions": { "sourceMap": true } }

  • app.ts

    throw 'some error in my typescript';

  • 开发工具控制台:

    app.ts:5Uncaught some error in my typescript(anonymous function) @ app.ts:5

2 个案例:

  • ts.config

    { "compilerOptions": { "sourceMap": true, "outFile": "src.js" } }

  • app.ts

    throw 'some error in my typescript';

  • 开发工具控制台:

    app.ts:5Uncaught some error in my typescript(anonymous function) @ app.ts:5

如果关闭了开发工具控制台,刷新页面,然后打开开发工具控制台,可以看到如下内容:

src.js:4 Uncaught some error in my typescript

但是如果你用打开的开发工具控制台再次刷新页面,你可以看到 ts 文件作为错误源。