Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 'Cannot read property 'ɵmod' of undefined' when importing custom module [Angular 11]

I'm trying to make a custom module that holds all my UI components, you can found it here: dawere-uic

It compiles and it works like a charm with the storybook I have on it, every UI component is working. The thing is when I try to use it on my main project I'm getting this error:

Uncaught TypeError: Cannot read property 'ɵmod' of undefined
  at getNgModuleDef (core.js:1117)
  at recurse (core.js:25171)
  at recurse (core.js:25182)
  at registerNgModuleType (core.js:25167)
  at new NgModuleFactory$1 (core.js:25281)
  at compileNgModuleFactory__POST_R3__ (core.js:28915)
  at PlatformRef.bootstrapModule (core.js:29161)
  at Module.zUnb (main.ts:11)
  at __webpack_require__ (bootstrap:79)
  at Object.0 (main.js:11)

It happens as soon as I import it in the app.module. Can anyone tell me what I'm doing wrong? I think it's worth mentioning though that I'm new to Angular.

like image 592
Portujua Avatar asked Mar 11 '21 16:03

Portujua


Video Answer


2 Answers

Simply just return the module.

 {
    path: 'auth',
    loadChildren: () =>
      import('./auth/auth.module')
        .then((a) => {
          return a.AuthModule;
        });
  },
like image 58
Tushar Gujrathi Avatar answered Nov 15 '22 00:11

Tushar Gujrathi


I got the same error but eventually found out that my lazy load script was wrong, that was what I had:

path: 'modulePath', loadChildren: () => import ('./exemple-module/exemple-module.module').then (m => { m.exemple-module })

This is what it should have been:

path: 'modulePath', loadChildren: () => import ('./exemple-module/exemple-module.module').then (m => m.exemple-module)

I did not return the module in the arrow function. Not sure if this helps, but this is the problem I had and how I solved it

like image 43
ebed meleck Avatar answered Nov 14 '22 22:11

ebed meleck