Angular 2 Error creating ng build AOT + lazy loading from another package

I have an angular 2 application which is the main entry for my application.

In this application, I install another angular npm package that has all the code for my modules.

This npm package is compiled as an angular library using AOT and published to private npm.

Here is an example application with errors. https://github.com/chorew/AngularSample

To see the problem:

  • clone repo
  • npm install
  • npm run dev: library

In the main application module, I have this lazy loaded route:

const routes: Routes = [
    {   path: 'underwriting',
        loadChildren: '@h2o/underwriting/src/underwriting/underwriting.module#UnderwritingModule' 
    }
];

The error appears when I run ng build --aotin the main application.

ERROR in ./src/$$_gendir async
Module not found: Error: Can't resolve 'C:\Users\Juan.Pablo\projects\POC\h2o.web\packages\h2o.app\src\node_modules\@h2o\underwriting\src\underwriting\underwrit
ing.module.d.ngfactory.ts' in 'C:\Users\Juan.Pablo\projects\POC\h2o.web\packages\h2o.app\src\$$_gendir'
@ ./src/$$_gendir async
@ ./~/@angular/core/@angular/core.es5.js
@ ./src/main.ts
@ multi ./src/main.ts

, @h2o/underwriting , .

ng build ( src, , src)

'C:\Users\Juan.Pablo\projects\POC\h2o.web\packages\h2o.app\src\node_modules\@h2o\underwriting\src\underwriting\underwrit
ing.module.d.ngfactory.ts'

'C:\Users\Juan.Pablo\projects\POC\h2o.web\packages\h2o.app\node_modules\@h2o\underwriting\src\underwriting\underwrit
ing.module.d.ngfactory.ts'
+4

Source: https://habr.com/ru/post/1674928/


All Articles