I have a multi-app angular-cli project with some code base sharing.
Basically, the structure looks like following:
- src - main application
- app.component - bootstrapped component
- app.module
- shared - shared application parts
- demo.component
- shared.module
- extension - second application supposed to extend the main one
- extension-app.component - bootstrapped component
- extension.module
SharedModule (which declares and exports the DemoComponent) is imported by both AppModule and ExtensionModule. DemoComponent is then added to templates of both AppComponent and ExtensionAppComponent.
Everything is working just fine when using JIT compiler (ng serve, ng serve --app extension), but AOT compiler fails saying:
Can't resolve '../../../src/app/demo/demo.component.ngfactory'
Looking into this generated file at GENDIR/app/demo/demo.component.ngfactory we get the following:
import * as i0 from './demo.component.css.shim.ngstyle';
import * as i1 from '@angular/core';
import * as i2 from './demo.component';
The last one import is the one that fails, because there is no 'demo.component' in the GENDIR/app/demo folder. Surprisingly the file imported as i0 does exist and contains appropriate styles.
UPDATE: looks like the problem is in ngc. It would neither work even if you add a paths alias in tsconfig.json. There are a couple of issues about it on github (https://github.com/angular/angular/issues/13487)