浏览器错误消息使用outFile引用正确的typescript文件 [英] Browser error messages referencing correct typescript file using outFile

查看:336
本文介绍了浏览器错误消息使用outFile引用正确的typescript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 tsconfig.json 中的 outFile 选项将我的typescript文件编译成一个.js文件。

我正在生成一个源地图。

虽然引用了typescript文件,但是不是。

I am using the outFile option in the tsconfig.json to compile my typescript files into one .js file.
I am generating a source map.
Error messages are not referenced to the typescript file though.

示例:

script.ts: throw'Error' code>

tsconfig.json:

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

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

编译tsc 1.6.2)将生成:

script.js: throw'错误

script.js.map:<$ cc{version:3,file:script.js,sourceRoot:,sources:[script.ts],names:[],mappings :AACA,MAAM,QAAQ,CAAC}

Compiling (tsc 1.6.2) will generate:
script.js: throw 'Error
script.js.map: {"version":3,"file":"script.js","sourceRoot":"","sources":["script.ts"],"names":[],"mappings":"AACA,MAAM,QAAQ,CAAC"}

浏览器的控制台(Chrome 47.0.2526.73 m)将显示:未捕获错误。 script.ts:1

The browser's console (Chrome 47.0.2526.73 m) will display: Uncaught Error. script.ts:1

这很好。

script.ts: throw'Error'

tsconfig.json:

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

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

编译(tsc 1.6.2)将生成:

app.js: throw'错误

app.js.map: {version:3,文件:app.js,sourceRoot:,sources:[script.ts],名称:[],映射:AACA,MAAM,QAAQ,CAAC / code>

Compiling (tsc 1.6.2) will generate:
app.js: throw 'Error
app.js.map: {"version":3,"file":"app.js","sourceRoot":"","sources":["script.ts"],"names":[],"mappings":"AACA,MAAM,QAAQ,CAAC"}

浏览器的控制台(Chrome 47.0.2526.73 m)将显示:未捕获的错误。 app.js:1

The browser's console (Chrome 47.0.2526.73 m) will display: Uncaught Error. app.js:1

它是 app.js 应该是 app.ts

如何让浏览器将错误消息引用到我的typescript文件?

How can I get the browser to reference error messages to my typescript files?

推荐答案

我使用了相同版本的Chrome浏览器。但是ts编译器版本是1.7.3

I have used the same version of Chrome browser. However ts compiler version is 1.7.3

开发工具控制台已打开。

Dev tools console is opened.

1例:


  • ts.config

  • ts.config

{
compilerOptions:{
sourceMap:true
}
}

app.ts

throw'some error in my typescript';

开发工具控制台:

app.ts:5在我的打字机(匿名功能)@ app中出现一些错误。 ts:5

2个案例:


  • ts.config

  • ts.config

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

app.ts

throw'some error in my typescript';

开发工具控制台:

app.ts:5在我的打字机中没有出现错误(匿名功能)@ app.ts:5

v工具控制台关闭,页面被刷新,然后您将打开开发工具控制台,然后您可以看到以下内容:

If a dev tools console is closed, the page is refreshed, then you will open the dev tools console, then you can see the following:

src。 js:4在我的打字机中没有收到一些错误

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

But if you refresh the page again with opened dev tools console, you can see ts file as a source of error.

这篇关于浏览器错误消息使用outFile引用正确的typescript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆