angular-cli build prod \"Runtime compiler is not loaded”

匿名 (未验证) 提交于 2019-12-03 08:44:33

问题:

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 

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?

回答1:

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 file is smaller than when using aot compilation but vendor.bundle js increases by approx 1,5 MB.



回答2:

This happens in @angular/cli@1.0.0-rc.2 when doing a production build (ng build -prod) while using the compiler class in your code.

To replace the compiler you'll want to use "dynamic component creation". See this SO:

.


Also, check if you're importing polyfills.ts

I was able to rid this by comparing my @angular/cli@1.0.0-rc2 project to a freshly scaffolded CLI project and noticed that polyfills.ts wasn't imported anywhere except in .angular-cli.json

For example, I was importing polyfills.ts in main.ts

import 'polyfills.ts'; // Remove this line import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';  import { AppModule } from './app/app.module'; import { environment } from './environments/environment';  if (environment.production) {   enableProdMode(); }  platformBrowserDynamic().bootstrapModule(AppModule); 

Polyfill.ts only need be in .angular-cli.json here:

...   "index": "index.html",   "main": "main.ts",   "polyfills": "polyfills.ts",   "test": "test.ts",   "tsconfig": "tsconfig.app.json", ... 

Duplicate:



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!