angular-cli build prod“未加载运行时编译器" [英] angular-cli build prod "Runtime compiler is not loaded”

查看:98
本文介绍了angular-cli build prod“未加载运行时编译器"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了ng build -prod并遇到了一个奇怪的错误,那就是 _zone_symbol__错误 :

I did ng build -prod and met a weird error that is _zone_symbol__error :

Error: Uncaught (in promise): Error: Runtime compiler is not loaded Error: Runtime compiler is not loaded at d (http://localhost:4200/polyfills.cd321326a3dfc08ceb46.bund

我没有在我的应用程序中手动使用编译器.最奇怪的是,错误似乎来自polyfills. 我该如何解决?

I am not using the compiler manually in my app. And the weirdest is that the error seems to come from the polyfills. How can i solve this?

推荐答案

对于我来说,它可以禁用构建的提前编译

In my case it works to disable Ahead-of-Time compilation for the build

ng build -prod --aot=false

通过这种方式,仍然可以打包和丑陋源代码,并包括即时编译器.

This way the source is still packed and uglyfied and Just-in-Time compiler is included.

main.bundle js文件比使用aot编译时要小,但是vendor.bundle js增加了约1.5 MB.

main.bundle js file is smaller than when using aot compilation but vendor.bundle js increases by approx 1,5 MB.

编辑2018-07-11

似乎有两种情况:

1)如果您的项目有意创建真正的动态组件,则目前唯一包含JIT编译器的方法似乎是在生产版本中禁用AOT.请参阅 https://github.com/angular/angular/issues/11780 讨论

1) If your project intentionally creates true dynamic components, currently the only way to include the JIT compiler seems to disable AOT for the production build. See https://github.com/angular/angular/issues/11780 for a discussion

2)如果您的项目不需要需要动态创建组件,并且您不知道为什么会发生错误,则禁用AOT可能是一种解决方法,但请注意缺点.如果没有AOT,则文件较大,并且用户启动应用程序所花费的时间更长.在这种情况下,调查在生产版本中为什么引用JIT编译器可能更合适.

2) If your project does not need to create components dynamically and you don't know why the error happens, disabling AOT can be a workaround but beware of the drawbacks. Without AOT you have larger file sizes and it takes longer for the user to start with your application. In this case it may be more appropriate to investigate why the JIT compiler is referenced in the production build.

有一些SO讨论( AngularCli和AOT:错误错误:未加载运行时编译器解决"运行时问题编译器未加载"(),这表明延迟加载使用'COMPILER_PROVIDERS'的第三方模块可能是导致错误的原因.在撰写本文时,他们还没有接受的答案.

There are some SO Discussions (AngularCli & AOT: ERROR Error: Runtime compiler is not loaded, Trouble shoot "Runtime compiler is not loaded") around which suggest that lazy loading a third party module which uses 'COMPILER_PROVIDERS' can be the reason for the error. At the time of writing they have no accepted answer though.

有关使用延迟加载模块时的另一个陷阱的描述,请参见此线程中Alexei的答案

For the description of another pitfall when using lazy loading modules see the answer of Alexei in this thread

这篇关于angular-cli build prod“未加载运行时编译器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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