我如何可以采取缩小的JavaScript的堆栈跟踪并运行它针对源的地图,以获得正确的错误? [英] How can I take a minified javascript stack trace and run it against a source map to get the proper error?

查看:120
本文介绍了我如何可以采取缩小的JavaScript的堆栈跟踪并运行它针对源的地图,以获得正确的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的生产服务器上,我已经精缩的JavaScript公布,我不包括它的地图文件,因为我不希望用户能够理解什么是基于错误的发生。

On our production server, I have minified javascript published and I'm not including a map file with it, because I don't want the user to be able to understand what's happening based on the error.

我有我写通过电子邮件角度异常(由$ exceptionHandler的捕获)转发给自己一个日志服务。不过,该堆栈跟踪近不可读:

I have a logging service I've written to forward the angular exceptions (caught by $exceptionHandler) to myself via email. However, this stack trace is near unreadable:

n is not defined
    at o (http://localhost:9000/build/app.min.js:1:3284)
    at new NameController (http://localhost:9000/build/app.min.js:1:3412)
    at e (http://localhost:9000/build/bower.min.js:44:193)
    at Object.g.instantiate (http://localhost:9000/build/bower.min.js:44:310)
    at b.$get (http://localhost:9000/build/bower.min.js:85:313)
    at d.compile (http://localhost:9000/build/bower.min.js:321:23333)
    at aa (http://localhost:9000/build/bower.min.js:78:90)
    at K (http://localhost:9000/build/bower.min.js:67:39)
    at g (http://localhost:9000/build/bower.min.js:59:410)
    at http://localhost:9000/build/bower.min.js:58:480 <ui-view class="ng-scope">

我想知道的是:是否有一个程序,我可以分析对通过映射文件中的实际非缩小的源$ C ​​$ C这个堆栈跟踪(或不通过,如果有另一种方式映射文件)

What I'm wondering is: Is there a program where I can analyze this stack trace against the actual non-minified source code via map file (or not via map file if there's another way)

推荐答案

您想要做的是分析源地图。这有没有关系网络浏览器。所有你需要做的是翻译缩小的参考到unminified资源。

What you want to do is parse the source maps. This has nothing to do with web browsers. All you need to do is translate the minified reference into the unminified resource.

如果您有任何的NodeJS经验已经有一个包,这是否适合你。

If you have any experience with NodeJS there is already a package that does this for you.

https://github.com/mozilla/source-map/

要安装该库

npm install -g source-map

创建一个名为issue.js

Create a file named "issue.js"

fs = require('fs');
var sourceMap = require('source-map');
var smc = new sourceMap.sourceMapConsumer(fs.readFileSync("./app.min.js.map","utf8"));
console.log(smc.originalPositionFor({line: 1, column: 3284}));

运行与节点文件

node issue.js

它不应该在原始文件到控制台从堆栈跟踪第一行输出的位置。

It should output the location in the original file to the console for first line from the stack trace.

注:我告诉你安装源全球地图的易用性,但您可以创建一个节点项目已经做了你需要什么,在本地安装它。

Note: I tell you install source-map globally for ease of use, but you could create a node project that does what you need and installs it locally.

这篇关于我如何可以采取缩小的JavaScript的堆栈跟踪并运行它针对源的地图,以获得正确的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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