question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Runtime compiler is not loaded in AOT service

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

app.js?1479195046940:141 Error: Runtime compiler is not loaded at t (app.js?1479195046940:141) at e.compileModuleAndAllComponentsAsync (app.js?1479195046940:141) at e.compileComponent (app.js?1479195046940:115)

Expected behavior Compiler can be loaded。

Minimal reproduction of the problem with instructions file:.service.ts

import {Injectable, ApplicationRef, Injector, ViewContainerRef, ComponentRef, ModuleWithComponentFactories, Compiler, Inject} from ‘@angular/core’;

@Injectable() export class ComponentLoaderService { public dynamicLoadModule : any;

public appViewContainerRef:ViewContainerRef;

constructor(public injector:Injector,
            public appRef:ApplicationRef,
            @Inject(Compiler) public compiler: Compiler
) {
}

setDynamicLoadModule(module :any) {
    this.dynamicLoadModule = module;
}
//APP view Container
setAppViewContainer(appViewContainer:any) {
    this.appViewContainerRef = appViewContainer;
}

/**
 * compile component
 */
compileComponent(componentSelector:string, viewContainerRef:any, callBack:any) {
    return this.compiler.compileModuleAndAllComponentsAsync(this.dynamicLoadModule)
      .then((moduleWithFactories:ModuleWithComponentFactories<any>) => {

          const factory = moduleWithFactories
            .componentFactories.find((x : any) => x.selector === componentSelector);

          let componentRef = viewContainerRef.createComponent(factory, 0);
          if (typeof callBack === 'function') {
              callBack(componentRef);
          }
      });
}

/**
 * Load global component
 * @param componentSelector
 * @param viewContainerRefV :  ViewContainerRef
 * @returns {any}
 */
loadGlobalComponent(componentSelector:string, option:any):any {
    option = option ? option : {};
    this.compileComponent(componentSelector, this.appViewContainerRef, (componentRef:any) => {
        if (typeof componentRef.instance.setOption === 'function') {
            componentRef.instance.setOption(option)
        }
    });
}

/**
 * 
 * @param templateLabel
 * @param viewContainerRef
 * @param option init data
 * @param callBack 
 * @returns {any}
 */
loadComponent(componentSelector:string, viewContainerRef:any, option?:any, callBack?:any):any {
    option = option ? option : {};

    this.compileComponent(componentSelector, viewContainerRef, (componentRef:any) => {
        if (typeof componentRef.instance.setOption === 'function') {
            componentRef.instance.setOption(option)
        }

        if (typeof callBack === 'function') {
            callBack(componentRef.instance);
        }
    });

}

}

// provide in shared module export class SharedModule { static forRoot(): ModuleWithProviders { return { ngModule: SharedModule, providers: [ {provide : ‘component-loader.service’, useClass: ComponentLoaderService } ] }; } }

//use service import {Injectable, Inject} from ‘@angular/core’;

@Injectable() export class DialogService {

constructor (
	@Inject('component-loader.service') private componentLoader: any
) {}

open(option : any) {
	if(option) {
		this.componentLoader.getGlobalComponent('bi-dialog', option);
	}
}

close() {

}

}

# //file : dynamic-load.module.ts import { NgModule, ModuleWithProviders } from ‘@angular/core’; import { FormsModule } from ‘@angular/forms’; import {DialogComponent} from ‘…/shared/components/page/dialog.component’;

@NgModule({ imports: [SharedModule,FormsModule], declarations: [ DialogComponent ] }) export class DynamicLoadModule { }

//I import DynamicLoadModule in app.component.ts import { DynamicLoadModule } from ‘./common/dynamic-load.module’;

//set DynamicLoadModule in appComponent this.componentLoaderService.setDynamicLoadModule(DynamicLoadModule);

Please tell us about your environment: mac phpstorm

  • Angular version: 2.1
  • Browser: [all | Chrome 54 ]
  • Language: [all | TypeScript 2.X | ES6/7 | ES5]

  • Node (for AoT issues): node --version = 6.9.1

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ashwinirajputcommented, Apr 17, 2017

Same issue Runtime compiler is not loaded when i am using plunker ng2-date-time-picker

2reactions
lacolacocommented, Nov 16, 2016

@sunnylearn I’m using RuntimeCompiler in platformBrowser with few hacks.

1: Add COMPILER_PROVIDERS into platformBrowser()

import { COMPILER_PROVIDERS } from '@angular/compiler';

platformBrowser(COMPILER_PROVIDERS).bootstrapModuleFactory(AppModuleFactory);

2: Provide RuntimeCompiler as Compiler

providers: [
  { provide: Compiler, useExisting: RuntimeCompiler }
]

This is not a standard way, so please don’t forget nobody knows when we can use this workaround until.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EXCEPTION: Runtime compiler is not loaded - Stack Overflow
When I used this approach AOT build would not work, failing with "Runtime compiler is not loaded": loadChildren: () => import('.
Read more >
Error: Runtime compiler is not loaded in angular6 --prod mode ...
It sounds like you were running your application in the JIT mode in v5 but then switched over to the AOT mode in...
Read more >
runtime compiler is not loaded angular 9, error
You're using the compileModuleSync from the Compiler service, which is called by the createDynamicTemplate method. The angular compiler cli is analyzing your ...
Read more >
Error: Runtime compiler is not loaded Angular 8 - Reddit
I am trying to load the routes from a JSON file.There is also a lazy loaded module in the routes.Everything works as expected...
Read more >
Angular compiler options
When you use ahead-of-time compilation (AOT), you can control how your application is compiled by specifying template compiler options in the TypeScript ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found