如何调试角度2的AOT故障 [英] How to debug angular 2 aot failures

查看:191
本文介绍了如何调试角度2的AOT故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由ng cli生成的angular 2应用.

-当我运行ng build(或)ng build --prod --aot = false并提供页面时,一切正常.
-但是,当我尝试通过运行ng serve --aot = true并启用服务来启用aot时,页面会因为多个DI错误而中断,如下所示

I have an angular 2 app generated by ng cli.

- When I run ng build (or) ng build --prod --aot=false and serve up the page things just work fine.
- But when I try to enable aot by running ng serve --aot=true and serve up, the page breaks with multiple DI errors like below

很难调试.关于如何调试这些问题的任何想法吗?

Very hard to debug. Any idea on how to debug these issues?

例外:没有提供选项的服务!
error_handler.js:59原始堆栈跟踪:
ErrorHandler.handleError @ error_handler.js:59
(匿名)@ application_ref.js:272
webpackJsonp.679.ZoneDelegate.invoke @ zone.js:229
onInvoke @ ng_zone.js:271
webpackJsonp.679.ZoneDelegate.invoke @ zone.js:228
webpackJsonp.679.Zone.run @ zone.js:113
(匿名)@ zone.js:509
webpackJsonp.679.ZoneDelegate.invokeTask @ zone.js:262
onInvokeTask @ ng_zone.js:262
webpackJsonp.679.ZoneDelegate.invokeTask @ zone.js:261
webpackJsonp.679.Zone.runTask @ zone.js:151
rainMicroTaskQueue @ zone.js:405

EXCEPTION: No provider for Options!
error_handler.js:59 ORIGINAL STACKTRACE:
ErrorHandler.handleError @ error_handler.js:59
(anonymous) @ application_ref.js:272
webpackJsonp.679.ZoneDelegate.invoke @ zone.js:229
onInvoke @ ng_zone.js:271
webpackJsonp.679.ZoneDelegate.invoke @ zone.js:228
webpackJsonp.679.Zone.run @ zone.js:113
(anonymous) @ zone.js:509
webpackJsonp.679.ZoneDelegate.invokeTask @ zone.js:262
onInvokeTask @ ng_zone.js:262
webpackJsonp.679.ZoneDelegate.invokeTask @ zone.js:261
webpackJsonp.679.Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:405

推荐答案

您是否有机会使用 angular2-logger ?我遇到了完全相同的错误,并且发现了,即使我实际上没有使用我必须提供它们以供--aot使用的选项.

Are you by any chance using: angular2-logger? I've had the exact same error and found out even though I don't actually use the Options I had to provide them for --aot to work.

例如:在您的AppModule中必须进行以下导入:

Eg: In your AppModule have to following import:

import {Logger, Options} from "angular2-logger/core";

然后在提供者列表中确保添加选项:

Then in you list of providers make sure you add Options:

providers: [
  Logger,
  Options // <-- this is key
]

这确保AOT包含选项".

That made the sure AOT included "Options".

现在,我如何找到答案?该错误提示您找不到选项".因此,我使用开发人员工具使用sourceMaps查看了生成的源代码(我查看了main.bundle.js).在那里,我搜索了字符串"Options",唯一的匹配也给了我最后的提示:

Now, how did I find out? The error gives you the hint it cant find "Options". So I used the Developer Tools to look at the generated sources using the sourceMaps (I looked at main.bundle.js). There I searched for the string "Options" and the only hit gave me also the final hint:

__WEBPACK_IMPORTED_MODULE_9_angular2_logger_core__["Options"])

现在,在查看了我还必须提供选项的文档之后,我才意识到.

Now thate made me realize after looking at the docs I had to provide the Options as well.

希望这会有所帮助. :)

Hope this helps. :)

这篇关于如何调试角度2的AOT故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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