Angular 8 Local Library import issue

571 views Asked by At

I have created one Angular custom Library which I need to use in multiple projects in different workspace. I will plan to publish Library to NPM once I test it properly locally. below is my Library code :

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AppbuttonComponent } from './appbutton.component';
import { CRMMaterialModule } from '../../material.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
  declarations: [AppbuttonComponent],
  imports: [
    BrowserAnimationsModule,
    CRMMaterialModule
  ],
  exports: [AppbuttonComponent]
})
export class AppbuttonModule { }

And Library Public API is like

export * from './lib/components/appbutton/appbutton.module';
export * from './lib/components/appbutton/appbutton.component';

Then I link my application (in different workspace) to my library. below is my appModule.ts file code

 imports: [
    BrowserModule,
    FormsModule,
    BrowserAnimationsModule,
    CoreModule,
    AppbuttonModule,
    RouterModule.forRoot(AppRoutes, { useHash: true })....

It builds proper but when I try to run application, it gives me below error:

Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.

Can Anyone help for this ? I'm stuck in this since 3 days.

0

There are 0 answers