在缩小的角度 javascript 中调试未知的提供程序 [英] Debugging Unknown provider in minified angular javascript

查看:18
本文介绍了在缩小的角度 javascript 中调试未知的提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难确定我的 angular 应用程序中有哪些方法会导致错误:

I'm having a hard time trying to pinpoint which, of the very many, methods I have in my angular app that would be causing the error:

未捕获的错误:[$injector:unpr] 未知提供者:nProvider <- n

这仅在 javascript 被捆绑后才会发生 &由 ASP.Net 缩小.

This only happens once the javascript has been bundled & minified by ASP.Net.

我已确保所有控制器和任何其他 DI 都在使用压缩安全方法,即我的控制器/服务等正在使用该方法:

I have ensured that all the controllers, and any other DI, is using the minification-safe method, I.E My controllers/service etc are using the method:

appControllers.controller('myCtrl', ['$scope', function($scope){
        //......
}]);

我已经浏览了我们应用程序中的每个 JS 文件 - 有很多......并且找不到任何违反这种注入依赖项方式的东西 - 尽管某处肯定有一个......

I've gone through every JS file in our app - there are a lot... and can't find anything that violates this way of injecting dependencies - though there must be one somewhere...

是否有更好的方法来确定可能导致此错误的方法?

Is there a better way to pinpoint which method could be causing this error?

谢谢

推荐答案

正如评论中提到的,这些是我尝试找到我的 JS 错误所采取的步骤.

As mentioned in the comments, These are the steps I took to try and find my JS error.

如果有其他更简单的解决方案,请随时发布,我可能会将其标记为已接受.

If there is another, easier, solution, please feel free to post it and I may mark it as accepted.

试图调试缩小的代码是一场噩梦.

Trying to debug minified code is a nightmare.

我最终做的是直接从 Chrome 中的检查器复制我缩小的 javascript.

What I eventually did was copy my minified javascript, directly from the inspector in Chrome.

然后我将 JS 粘贴到 http://www.jspretty.com/ - 我试过 http://jsbeautifier.org/ 但发现他们的网站被这么大的 JS 代码冻结了.

I then pasted the JS into http://www.jspretty.com/ - I had tried http://jsbeautifier.org/ but found their site froze with such large JS code.

一旦它漂亮"了,我就在我的解决方案中创建了一个 test.js 文件,并将现在更易于阅读的代码粘贴到其中.

Once it was 'pretty-fied' I created a test.js file in my solution and pasted the, now easier to read code, into it.

在我的 _layout 中注释掉 @script 标记并添加指向 test.js 文件的链接的快速步骤,我现在准备调试阅读 Javascript 代码块.

Quick step to comment out the @script tag in my _layout and add a link to the test.js file and I was ready to debug a now, far easier to read, chunk of Javascript.

遍历调用堆栈仍然很笨拙,尽管现在您可以看到实际的方法,这使它变得不那么不可能了.

It is still pretty awkward to traverse the call stack, though now you can see actual methods it makes it far less impossible.

这篇关于在缩小的角度 javascript 中调试未知的提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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