简体   繁体   English

错误:没有ErrorHandler。 是否包含平台模块(BrowserModule)? 尝试从jsf页面加载angular应用时

[英]Error: No ErrorHandler. Is platform module (BrowserModule) included? when trying to load angular app from jsf page

We have a legacy app that includes POJavascript, prototype, jquery. 我们有一个遗留应用程序,其中包括POJavascript,原型,jquery。

We are rewriting the app in angular one part at a time. 我们一次将应用程序重写为一个角度。 Currently we have rewritten some part with angular4. 目前,我们已经用angular4重写了一部分。 We are using webpack to bundle angular4 app, including angular bundles in application's landing page which worked well; 我们正在使用webpack捆绑angular4应用程序,包括在应用程序的登录页面中运行良好的角度捆绑程序; webpack dev server is also working good. webpack开发服务器也运行良好。

Now, I am trying to upgrade to angular CLI and angular v6.2.1. 现在,我正在尝试升级到角度CLI和角度v6.2.1。 So, I created a new project with CLI and then copied my angular4 source code into this new project, resolved all errors. 因此,我使用CLI创建了一个新项目,然后将我的angular4源代码复制到了这个新项目中,解决了所有错误。 CLI is spitting out all required scripts. CLI正在吐出所有必需的脚本。 I am including these scripts in my landing page. 我将这些脚本包含在登录页面中。

With prod build it doesn't show any error in console and angular app doesn't load. 使用prod build,它不会在控制台中显示任何错误,并且不会加载angular应用。 I tried with ng serve, by including https://localhost:4200/xxx scripts in landing page, and it is showing below error in console... 我尝试通过在登录页面中包含https://localhost:4200/xxx脚本来进行ng服务,它在控制台中显示以下错误...

NOTE : angular App works if directly accessed (https://localhost:4200) without any errors; 注意 :如果直接访问(https://localhost:4200)而没有任何错误,则Angular App可以运行; but I need to access this through my legacy app's landing page, as lot of other things gets initialized and we need to release part by part. 但是我需要通过旧版应用的登录页面进行访问,因为许多其他事情已经初始化,因此我们需要部分地发布。 I think this is something related to zone, but can't figure out the exact issue. 我认为这与区域相关,但无法找出确切的问题。

Error: No ErrorHandler. Is platform module (BrowserModule) included?
Stack trace:
["./node_modules/@angular/core/fesm5/core.js"]/PlatformRef.prototype.bootstrapModuleFactory/<@https://localhost:4200/vendor.js:43138:23 [angular]
forkInnerZoneWithAngularBehavior/zone._inner<.onInvoke@https://localhost:4200/vendor.js:42646:24 [angular]
["./node_modules/@angular/core/fesm5/core.js"]/NgZone.prototype.run@https://localhost:4200/vendor.js:42560:16 [<root>]
["./node_modules/@angular/core/fesm5/core.js"]/PlatformRef.prototype.bootstrapModuleFactory@https://localhost:4200/vendor.js:43133:16 [<root>]
["./node_modules/@angular/core/fesm5/core.js"]/PlatformRef.prototype.bootstrapModule/<@https://localhost:4200/vendor.js:43175:53 [<root>]
scheduleResolveOrReject/<@https://localhost:4200/polyfills.js:3194:29 [<root>]
drainMicroTaskQueue@https://localhost:4200/polyfills.js:2917:25 [<root>]
["./node_modules/zone.js/dist/zone.js"]/</ZoneTask.invokeTask@https://localhost:4200/polyfills.js:2822:21 [<root>]
patchEventTarget/invokeTask@https://localhost:4200/polyfills.js:3862:9 [<root>]
patchEventTarget/globalZoneAwareCallback@https://localhost:4200/polyfills.js:3888:17 [<root>]

Finally, I found the root cause of this issue - Array.from of PrototypeJS was conflicting with angular . 最后,我发现了此问题的根本原因-PrototypeJS的Array.from与angular冲突

Following code from compiler.js of angular refers to Array.from that was being initialized from prototypeJS (my legacy app uses it) 以下来自angular的compiler.js的代码引用的是从prototypeJS初始化的Array.from(我的旧版应用程序使用它)

function dedupeArray(array) {
    if (array) {
        return Array.from(new Set(array));
    }
    return [];
}

To resolve this issue save angular version of Array.from and re-assign after prototype script loads... 要解决此问题,请保存Array.from的Angular版本,并在加载原型脚本后重新分配...

<!-- 1. include Angular lib scripts -->
<script type="text/javascript" src="https://localhost:4200/runtime.js"></script>
<script type="text/javascript" src="https://localhost:4200/polyfills.js"></script>
<script type="text/javascript" src="https://localhost:4200/styles.js"></script>
<script type="text/javascript" src="https://localhost:4200/vendor.js"></script>
<!-- 2. save angular version of Array.from -->
<script> var ngArrayFrom = Array.from; </script>
<!-- 3. include Prototype script -->
<script type="text/javascript" src="/prototype.js"></script>
<!-- 4. re-assign Array.from -->
<script> Array.from = ngArrayFrom; </script>
<!-- 5. include angular app script -->
<script type="text/javascript" src="https://localhost:4200/main.js"></script>

It is working good; 运行良好; But I don't know if this is the best way and if there are any other conflicting scripts. 但是我不知道这是否是最好的方法,是否还有其他冲突的脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM