angular6 feature module lazy loading throwing error TypeError: undefined is not a function

I had the same problem, the cause for me was that i was importing the lazy loaded module in my app module.


This error is firing after some recompilation when ng serve is running, and after that, it shows always. Restarting ng serve - solved this problem.

Important!

Using loadChildren as function - is Not lazy loading:

{path: 'admin', loadChildren:() => AdminModule } //not lazy loading

cause you need to import the lazy module in the routing module.

For Lazy loading, you must send the path to the lazy module - as String!

{path: 'admin', loadChildren:'app/admin/admin.module#AdminModule'} // This is lazy loading

I have also faced the same problem while using Angular-7 and Angular CLI: 7.1.3 and tried to find some solution. It is solved for me by removing import statement of lazy loaded module from app.module file.

// remove this from app.module and app-routing.module file and it will work fine
import { AdminModule } from "./admin/admin.module";

My project configuration for reference