0

I am trying to split the Angular 7.0 app to feature modules.

All of the of the modules need the third party module and the third party module (lets call it ModuleX) imports 'BrowserModules'.

Note: ModuleX does not export 'BrowserModules'

Here is the dependencies of modules:

AppModule 
          >> MainComponent >> Requires ModuleX
ModuleB
          >> Component b-1 >> Requires ModuleX
ModuleC 
          >> Needs to import Module B 
          >> Module C -1 >> ModuleX
SharedModule
          

Here is how I constructed the AppRouting routing:

const routes : Routes = [
         {
              path: '',
              component: MainComponent,
              children: [
                  {
                      path: 'project',
                      loadChilderen: './c/c.module#CModule'
                  }
              ]
         }
]

Here is how modules are defined :

@NgModule({
  imports:      [ SharedModule, ModuleX.forRoot(), AppRoutingModule],
  declarations: [ MainComponent ],
  bootstrap:    [ MainComponent ]
})
export class AppModule { }

......

@NgModule({
  imports:      [ CommonModule ]
  declarations: [ ....],
})
export class SharedModule{ }

......

@NgModule({
  imports:      [ SharedModule, ModuleX]
  declarations: [ MainComponent ],
  bootstrap:    [ MainComponent ]
})
export class ModuleB{ }

......

   @NgModule({
      imports:      [ SharedModule, ModuleX, ModuleB]
      declarations: [ MainComponent ],
      bootstrap:    [ MainComponent ]
    })
    export class ModuleC{ }

When I try to access 'project' in the browser, I see the following error :

'Error: BrowserModule has already been loaded. if you need to access to common directives such as NgIf and NGFor from a lazy loaded module, import Common module.' The third party module has 'forRoot'

I put a break point in 'BrowserModule' ctro and noticed that the error thrown after the following call :

(window[webpackJsonp] = .....).push([['c-c-module-factory....)

Is this a problem with ModuleX or how I have designed the feature modules ?

Babak Fakhriloo
  • 2,076
  • 4
  • 44
  • 80

0 Answers0