Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngmodule is not a subtype ngmoduletype

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?

like image 505
poopp Avatar asked May 05 '20 13:05

poopp


Video Answer


3 Answers

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)
}

like image 95
lucaasnp_ Avatar answered Oct 13 '22 15:10

lucaasnp_


I also had this issue.

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

like image 33
jaime martin Avatar answered Oct 13 '22 14:10

jaime martin


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.

like image 2
user-12410035 Avatar answered Oct 13 '22 14:10

user-12410035