I'm building an app that need to have lazy loaded module. Everything is working fine on dev mode. When I try to prepare prod dist I have problems with lazy loaded module.
Deployment to prod:
- I'm trying to use this angular-seed: https://github.com/mgechev/angular-seed.
- Change APP_BASE in file seed.config.ts: APP_BASE = argv['base'] || '/angular-seed-master';
- Build command: npm run build.prod.aot (similar problem with build.prod)
- copy files to apache-tomcat-8.5.4\webapps\angular-seed-master\
App is starting fine, but when I try to open lazy loaded module I get following error:
__zone_symbol__error
:
Error: Uncaught (in promise): TypeError: System.import is not a function TypeError: System.import is not a function at t.loadFactory (http://127.0.0.1:8080/angular-seed-master/js/app.js?1487588806074:15:566) at t.load (http://127.0.0.1:8080/angular-seed-master/js/app.js?1487588806074:15:151) at t.loadModuleFactory (http://127.0.0.1:8080/angular-seed-master/js/app.js?1487588806074:14:8371) at t.load (http://127.0.0.1:8080/angular-seed-master/js/app.js?1487588806074:14:8103) at e.project (http://127.0.0.1:8080/angular-seed-master/js/app.js?1487588806074:12:21324)
I was able to reproduce this problem just by converting about.module from the seed into lazy loaded module. After doing changes listed below about.module is lazy loaded in dev mode:
app-routing.module.ts (add lazy load path)
@NgModule({
imports: [
RouterModule.forRoot([
{ path: 'about', loadChildren: 'app/about/about.module#AboutModule' },
/* define app module routes here, e.g., to lazily load a module
(do not place feature module routes here, use an own -routing.module.ts in the feature instead)
*/
])
],
exports: [RouterModule]
})
export class AppRoutingModule { }
about-routing.module.ts (change path from 'about' to '' because it is relative to the root router now)
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AboutComponent } from './about.component';
@NgModule({
imports: [
RouterModule.forChild([
{ path: '', component: AboutComponent }
])
],
exports: [RouterModule]
})
export class AboutRoutingModule { }
app.module.ts (remove import of AboutModule)
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { APP_BASE_HREF } from '@angular/common';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { HomeModule } from './home/home.module';
import { SharedModule } from './shared/shared.module';
@NgModule({
imports: [BrowserModule, HttpModule, AppRoutingModule, HomeModule, SharedModule.forRoot()],
declarations: [AppComponent],
providers: [{
provide: APP_BASE_HREF,
useValue: '<%= APP_BASE %>'
}],
bootstrap: [AppComponent]
})
export class AppModule { }
What alterations need to be done to the seed in order to have lazy loading working ?