Angular 5 lazy loading Error: Cannot find module

前端 未结 8 1752
栀梦
栀梦 2021-01-02 08:13

I would like to use lazy loading but I can not understand why it does not work, it gives me error \"Cannot find module\".
This is my environment:
- Angular 5.2.1

8条回答
  •  一整个雨季
    2021-01-02 08:40

    The currently accepted answer, which proposes to exchange the value of loadChildren from a string to a function, removes the possibility of AOT compilation when doing a production build.

    What worked for me, was 1) use absolute paths 2) Add the lazy loaded modules as a string array in angular.json under projects > 'projectname' > architect > build > options > lazyModules. The paths should be the same as defined under loadChildren.

    So, in your case, I think this should work in your routing module:

    loadChildren: 'app/components/users/users.module#UsersModule'
    

    And in angular.json, add this at the location specified above:

    lazyModules: ["app/components/users/users.module"]
    

提交回复
热议问题