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

做~自己de王妃 提交于 2019-12-03 04:24:27

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
sharad jain

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

I faced the same issue solved it like:-

  1. run => ng serve --aot
  2. Removed the module from import of the root module because i was already using module in the routing in loadChildren section.

By using both of the ways i was able to run the application. So, you can try any one of these.

Tri Vo

We didn't need to import AdminModule to app.module

Remove this from app.module and app-routing.module file and it will work fine.

import { AdminModule } from "./admin/admin.module";
{path: 'admin', loadChildren:() => AdminModule }

try this. this is the solution to the problem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!