“Please add a @NgModule annotation” Error on Angular2

后端 未结 4 558
慢半拍i
慢半拍i 2021-02-08 12:20

I have made a custom angular2(5.0.x) module that looks like this :

import { GuageService } from \'./services/guage.service\';
import { NgModule } from \'@angular         


        
4条回答
  •  情书的邮戳
    2021-02-08 13:06

    If you are using Angular 5.0 you need to add "annotationsAs": "decorators" to the "angularCompilerOptions" for your package. Angular 5 introduced new optimizations and by default the decorators are removed on compile because they are not needed at runtime. This does not work for packages as you already discovered. You can read about this in the Angular 5 announcement blog the "Build Optimizer" paragraph mentions this. Version 5.0.0 of Angular Now Available

    I use this settings in my angular packages:

    "angularCompilerOptions": {
          "skipTemplateCodegen": true,
          "skipMetadataEmit": false,
          "strictMetadataEmit": true,
          "annotationsAs": "decorators"
       }
    

提交回复
热议问题