I'm hitting an issue with AOT compilation and custom packages. In my scenario I have an Angular/Cli project which installs my own package (Package A). Package A has a dependency on Package B which contains a service.
NPM install of Package A results in a node_modules structure of:
- node_modules
- package_a
- (package_a files)
- node_modules
- package_b
- (package_b files)
- test.service.ts
- package_b
- package_a
This appears to make sense, as Package A is dependent on a certain version of Package B, therefore Package B is installed within a nested node_modules folder. Also I have ensured Package A exports TestService from Package B so it will be available.
The issue I have is when trying to access the Service in Package B from the main project:
app.component.ts
import { Component } from '@angular/core';
import { TestService } from 'package_a';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [TestService]
})
export class AppComponent {
constructor(
private log: TestService,
) {}
ngOnInit(): void {
// call function from package_b
}
}
First off, when I run ng serve everything works perfectly, no issues at all. However, when I try to build the project using AOT compilation, it fails with an error: ERROR in ... Cannot find module.
If I install Package B separately, so there is an instances of it in the main node_modules directory, the whole thing works. Even if the nested version is different, it will use the nested version correctly as defined in Package A.
- node_modules
- package_a
- (package_a files)
- node_modules
- package_b [version 1.0.0]
- (package_b files)
- test.service.ts
- package_b [version 1.0.0]
- package_b [version 2.0.0]
- (package_b files)
- test.service.ts
- package_a
Any ideas how I can stop the need for the additional installation of Package B? Is there something I'm missing to point to the nested version before the main version?