“Please add a @NgModule annotation” Error on Angular2

后端 未结 4 578
慢半拍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:17

    This is most likely an issue with the way your npm package is being created. In your package.json for your GuageModule are you defining a main? This should point to the entry point to your npm package. Here is an example of mine.

    "main": "./dist/module.js",
    

    Then if you want typings from GuageModule in your main app you'll need to go to your tsconfig.json and under compilerOptions set declaration to be true to generate the typings files.

    "compilerOptions": {
      ...
      "declaration": true
      ...
    },
    

    Then finally in your package.json you will need to point to the entry point for your typings file.

    "types": "./src/app/layout.module.d.ts"
    

    Now you should be able to import your module and have typings on the module that you imported. Hope this helps!

提交回复
热议问题