Currently, I am in need of assistance, pointers, or guidance in debugging and understanding an issue with a derived class that extends a service provided by a library in an Angular 6 project.
I am working on migrating an existing Angular 5.x project to the new workspace format for angular.json
in Angular 6 projects.
My current project includes an Angular application and a separate shared NgModule
that offers services and other features. This shared module will be utilized in multiple applications structured like this:
project-root/
library/
main-app/
other-app/
In my Angular 5 codebase, the shared library is linked into main-app as TypeScript source files using npm link
, which suits our team workflow even though it is not recommended by the Angular CLI team.
In the Angular 6 app, the library
is set up as a library project within angular.json
, built accordingly, and incorporated into the project through path configuration in tsconfig.json
. The workspace follows the standard layout for Angular 6 projects:
workspace-root/
dist/...
node_modules/...
projects/
library/
src/lib/...
main-app/
src/app/...
other-app/
...
Mostly, the services from the library are used without any modifications, but occasionally they are extended in main-app (or other-app) to cater to application-specific requirements. This setup functions seamlessly in Angular 5; however, in Angular 6, I encounter an error when trying to load the page while running ng serve
:
Object prototype may only be an Object or null
The warning is triggered at this line of code:
export class FooService extends FooBaseService { // ...
--------------------------------^
During the bootstrap process, FooBaseService is found to be 'undefined' when attempting to instantiate FooService.
After conducting some research, it appears that this error is typically linked to circular dependency issues, though I believe that might not be the case here. No circular dependency warnings are raised during the library build or when building main-app. Moreover, performing madge -c
doesn't detect any circular dependencies in either dist/library
or dist/main-app
.
I am currently at a loss regarding how to proceed with resolving this issue. Are there any individuals well-versed in Angular 6's handling of module-provided services who could offer some insights on how to tackle this problem?