I have simple angular library project named "test" with only one component displaying material icon. I have built it (ng build test)
My library module:
@NgModule({
declarations: [
TestComponent
],
imports: [
],
exports: [
TestComponent
]
})
export class TestModule { }
I want to test this library in my angular application. I have added library in app.module.ts:
import {TestComponent} from '../../dist/test'
and
@NgModule({
imports: [
TestComponent,
I'm using this component but unfortunatelly i get an error during ng serve command:
Error: ../../dist/test/lib/test.component.d.ts:3:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.
This likely means that the dependency which declares TestComponent has not been processed correctly by ngcc.
CodePudding user response:
You should import TestModule into AppModule, not TestComponent
CodePudding user response:
The correct way to do this is to define an Angular TestModule
in your library and have it include TestComponent
in its declarations array. Then, you can import that module in your AppModule
.
Otherwise, you'd have to include TestComponent
directly in AppModule
declarations
, which beats the purpose of having a library.