Just like in this particular inquiry, I crafted a unique Angular library (using Angular CLI 7.2.0) which consists of various feature modules:
MyLibraryModule
FeatureModule1
SomeComponent1
FeatureModule2
SomeComponent2
My goal is to selectively import only one feature module into my main application, similar to how Angular Material modules are imported (
import { MatButtonModule } from '@angular/material';
):
import { FeatureModule1 } from 'my-library';
...
@NgModule({
imports: [
...,
FeatureModule1,
]
})
...
This approach leads to the following error (while building the main project):
ERROR in : Unexpected value 'FeatureModule1 in ./node_modules/my-library/my-library.d.ts'
imported by the module 'AppModule in ./src/app/app.module.ts'.
Please add a @NgModule annotation.
However, when I directly import the library module (
import { MyLibraryModule } from 'my-library';
) into my primary application, everything functions smoothly.
The structure of my-library.module.ts appears as follows:
import { NgModule } from '@angular/core';
import { FeatureModule1 } from './feature-module-1/feature-module-1.module';
import { FeatureModule2 } from './feature-module-2/feature-module-2.module';
@NgModule({
imports: [ FeatureModule1, FeatureModule2 ],
exports: [ FeatureModule1, FeatureModule2 ],
})
export class MyLibraryModule{ }
The public_api.ts
file handles the export of all modules.
I suspect that the issue lies within the packaging process, as this setup works flawlessly in my testing project located in the same directory as the library.
Attempts to align the building process with that of @angular/material
have been made, although it seems they follow a slightly different approach compared to the official methods.