I have an angular 2 app that is the main entry for my application.
In this app I'm installing another angular npm package that has all the code for my modules.
This npm package is compiled like a angular library using AOT and its published to a private npm.
Here is a sample app with the errors. https://github.com/chorew/AngularSample
To see the problem:
- clone the repo
- npm install
- npm run dev:library
In the main app 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 the ng build --aot in the main app.
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
It seams that the package name @h2o/underwriting is not properly translated into the path and since its the base for the module path it produces that error.
ng build is trying to find (check the extra src, like if the module is inside the main app 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'
when it should be
'C:\Users\Juan.Pablo\projects\POC\h2o.web\packages\h2o.app\node_modules\@h2o\underwriting\src\underwriting\underwrit
ing.module.d.ngfactory.ts'