Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR in ** is not an NgModule

I have this NgModule:

@NgModule({
    imports: [
        CommonModule
    ],
    exports: [
        SP21LoadingBar
    ],
    declarations: [SP21LoadingBar]
})
export class SP21LoadingBarModule { }

The Cli ist telling me

ERROR in SP21LoadingBarModule is not an NgModule

Please notice: If i take the code and put it into my project it works fine. But as soon as I take the module (and component) out of my project and put it into a npm package, i get that error.

Angular is used in 2.3.1, Angular CLI 1.0.0-beta.24, Typescript 2.0.10

like image 611
Stefan S Avatar asked Jan 16 '17 10:01

Stefan S


People also ask

What are bootstrap in Ngmodules?

The bootstrap property or key of the NgModule decorator specifies which component should be loaded by Angular when the app-level module loads. Angular reads the bootstrap metadata and loads the app-level component, called AppComponent .

What is default module in Angular?

Every application has at least one Angular module, the root module, which must be present for bootstrapping the application on launch. By convention and by default, this NgModule is named AppModule .

What is the root module in Angular application?

Every Angular application has at least one NgModule class, the root module, which is conventionally named AppModule and resides in a file named app. module. ts . You launch your application by bootstrapping the root NgModule.


2 Answers

The FINAL solution:

You must compile your library using the Ahead-Of-Time compiler (ngc). It will add some metadata that allos the project that includes the library to read it.

Please, have a look on the follow links:

https://angular.io/docs/ts/latest/cookbook/aot-compiler.html https://medium.com/@cyrilletuzi/how-to-build-and-publish-an-angular-module-7ad19c0b4464#.9y88ipdk7

like image 100
Lupe Avatar answered Oct 11 '22 18:10

Lupe


You must use ngc (@angular/compiler-cli) to compile your library, as opposed to using tsc directly. Is this the case for you?

like image 44
Jose Enrique Avatar answered Oct 11 '22 17:10

Jose Enrique