Alo*_*lon 5 javascript typescript systemjs
我正在使用System.js加载用TypeScript编写的模块.System.js将我的原始代码包装在一个函数中,因此当我的代码中出现错误并尝试在Chrome开发人员工具中看到它时,单击错误只会将我带到JavaScript文件的第一行,其中有一个声明System.js添加的包装函数,而不是原始TypeScript文件中的正确行.
通常这不是问题,因为System.js将自己的堆栈跟踪添加到错误的末尾并单击它会将我带到原始TypeScript文件中没有包装函数的正确行.
但是,有时System.js不包含整个堆栈跟踪,那么Chrome生成的原始堆栈跟踪是查看错误行的唯一位置,但问题是单击它会将我带到JavaScript文件而不是TypeScript一个,并且到第一行,而不是正确的,如上所述.
我的问题:这是System.js中的错误还是我做错了什么?
为了使它更容易理解,我将在这里添加我的代码并解释方案.但请记住,我不会尝试修复我的代码,而是要了解为什么我无法通过开发人员工具找到正确的错误行.
所以这是我的System.js声明和配置:
<script src="/assets/libs/systemjs-master/dist/system-polyfills.js"></script>
<script src="/assets/libs/systemjs-master/dist/system.src.js"></script>
<script>
System.config({
defaultJSExtensions: true,
transpiler: 'typescript',
});
System.import('app.module')
.then(null, console.error.bind(console));
</script>
Run Code Online (Sandbox Code Playgroud)
这是app.module(System.js加载的根文件):
import './angular-1.4.7'
import './angular-route.min'
import {User} from "./classes";
import {Post} from "./classes";
import {BlogModel} from "./model"
var app: angular.IModule = angular.module("blogApp", ["ngRoute"]);
var model: BlogModel = new BlogModel();
app.run(function($http: angular.IHttpService): void{
$http.get("/user-context/current-user")
.success(function(currentUser: User): void{
if(currentUser.userName) {
model.currentUser = currentUser;
}
});
...
});
...
Run Code Online (Sandbox Code Playgroud)
产生错误的行:
$http.get("/user-context/current-user")
Run Code Online (Sandbox Code Playgroud)
这是我得到的完整堆栈跟踪:
正如您所看到的,正确的错误行仅显示在OOTB开发人员工具堆栈跟踪中,但不显示在System.js中(50%的时间确实显示实际错误行,并且应该始终执行此操作).
当我点击OOTB开发人员工具堆栈跟踪中的错误行时,我只是突出显示第一行的这个文件:
(function(require, exports, module, __filename, __dirname, global, GLOBAL) { //this line is highlighted
require('./angular-1.4.7');
require('./angular-route.min');
var model_1 = require("./model");
var app = angular.module("blogApp", ["ngRoute"]);
var model = new model_1.BlogModel();
app.run(function ($http) {
$http.get("/user-context/current-user") //but this is the line that should be highlighted
.success(function (currentUser) {
if (currentUser.userName) {
model.currentUser = currentUser;
}
});
...
});
...
});
//# sourceMappingURL=app.module.js.map
}).apply(__cjsWrapper.exports, __cjsWrapper.args);
Run Code Online (Sandbox Code Playgroud)
我的问题:这是System.js中的错误还是我做错了什么?
任何帮助将深表感谢!
此问题已报告并已关闭:Javascript 错误未链接到原始来源?
Chrome 控制台将错误指向第 1 行是常见的情况:Chrome 似乎报告错误的行。
也可以尝试使用其他浏览器,因为这可能是浏览器问题。另一种可能性是文件损坏,如此处所述。
| 归档时间: |
|
| 查看次数: |
758 次 |
| 最近记录: |