A
A
Al2019-01-10 14:28:58
Angular
Al, 2019-01-10 14:28:58

Why does the application crash with the error "undefined is not iterable" when building AOT?

I'm using the Compiler from "@angular/core" to create components on the fly. Normal assembly works fine, the application works without problems.
But, when I build with the --prod flag , it includes the following build options:

"optimization": true,
"outputHashing": "none",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"serviceWorker": true

After that, when the createCompiler() method is called, an error occurs:
undefined is not iterable (cannot read property Symbol(Symbol.iterator))

This is how my module in which the compiler is created looks like:
export function createJitCompiler() {
  return new JitCompilerFactory().createCompiler([{useJit: true}]);
}

@NgModule({
  imports: [
    CommonModule
  ],
  exports: [
    DynamicComponent
  ],
  declarations: [
    DynamicComponent
  ]
})
export class DynamicLoaderModule {
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: DynamicLoaderModule,
      providers: [
        {provide: Compiler, useFactory: createJitCompiler},
        {provide: NgModuleFactoryLoader, useClass: ModuleLoader}
      ]
    }
  }
}

I read in this article that if you use the AOT assembly, then the compiler will not be available at runtime. And they also write there that to solve this problem, you can create a separate module with a service, where you will need to manually add the compiler.
I did as it says, but the problem still persists. Angular version 7.0.1.
Has anyone solved similar problems? Or did I miss something?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur Mustafin, 2019-01-11
@virtual_hack2root

Look here JIT

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question