17

I use angular 9 and I want to do lazy load and I do app-routing

{
    path: '', loadChildren: () => import("./components/login/login.module")//.then(m =>
     // m.LoginModule)
  }

and after I create login module:

@NgModule({
    declarations: [LoginComponent],
    imports: [
        CommonModule,
        FormsModule,
        LoginModuleRouting

    ],
    providers:[]
})
export class LoginModule { }

and routing:

const routes: Routes = [
  {
    path: '', component: LoginComponent,

  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})


export class LoginModuleRouting { }

the proble is that when I call ng serveand I go on `http://localhost:4200/, I obtain this exception:

core.js:6237

 ERROR Error: Uncaught (in promise): Error: ASSERTION ERROR: NgModule '[object Module]' is not a subtype of 'NgModuleType'. [Expected=> null != null <=Actual]
Error: ASSERTION ERROR: NgModule '[object Module]' is not a subtype of 'NgModuleType'. [Expected=> null != null <=Actual]

I don't knwo what it means. Anyone can help me?

poopp
  • 1,297
  • 2
  • 13
  • 23

5 Answers5

11

I don't know why but you have commented out your login module on loadChildren() here:

{
path: '', 
loadChildren: () => import("./components/login/login.module")//.then(m =>
     // m.LoginModule)
}

and it should be:

{
path: '', 
loadChildren: () => import("./components/login/login.module").then(m => m.LoginModule)
}

lucaasnp_
  • 119
  • 1
  • 4
8

I also had this issue.

My problem was that I declared the NgModule without @. Adding it fixed the message.

jaime martin
  • 91
  • 1
  • 4
3

I know that the original cause of this was because of promise resolution being commented out, but I wanted to add another cause since this is the highest hit on Google for this error and there are multiple causes.

This can also be caused if you're trying to use a component as a module. Using component: MyComponentName instead of loadChildren: () => import('./my-component.component').then( m => m.MyComponent) will resolve this issue too. If you intended it to be a module, you can use ng generate module to create a module instead if you want to delegate routing to another module.

user-12410035
  • 277
  • 4
  • 2
0

Just uncomment the end of your lazy loaded module.

{
   path: '',
   loadChildren: () => import('./components/login/login.module').then((m) => m.LoginModule),
}
Elikill58
  • 4,050
  • 24
  • 23
  • 45
0

this problem I faced was because of using standalone in my angular component and then using loadChildren with lazy loading route in app.routes.ts. All I had to do was changing loadChildren to loadComponent

in app.routes.ts was

{
  path: 'login',
  loadChildren: () => import('./pages/login-page/login-page.component').then( m => m.LoginPageComponent)
},

and it should be

{
  path: 'login',
  loadComponent: () => import('./pages/login-page/login-page.component').then( m => m.LoginPageComponent)
},
Binary_Hits00
  • 570
  • 6
  • 7