我有这个NgModule:
@NgModule({
imports: [
CommonModule
],
exports: [
SP21LoadingBar
],
declarations: [SP21LoadingBar]
})
export class SP21LoadingBarModule { }
Cli告诉我
ERROR in SP21LoadingBarModule is not an NgModule
请注意:如果我把代码放到我的项目中,它可以正常工作。但是一旦我从我的项目中取出模块(和组件)并将其放入npm包中,我就会收到该错误。
Angular用于2.3.1, Angular CLI 1.0.0-beta.24, Typescript 2.0.10
答案 0 :(得分:4)
最终解决方案:
您必须使用Ahead-Of-Time编译器(ngc)编译库。它将添加一些元数据来分配包含库的项目来阅读它。
请查看以下链接:
https://angular.io/docs/ts/latest/cookbook/aot-compiler.html https://medium.com/@cyrilletuzi/how-to-build-and-publish-an-angular-module-7ad19c0b4464#.9y88ipdk7
答案 1 :(得分:1)
您必须使用ngc
(@ angular / compiler-cli)来编译库,而不是直接使用tsc
。这是你的情况吗?
答案 2 :(得分:0)
它使用以下依赖项:
{
"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/material": "^2.0.0-beta.0",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"@angular2-material/button": "^2.0.0-alpha.8-2",
"@angular2-material/card": "^2.0.0-alpha.8-2",
"@angular2-material/checkbox": "^2.0.0-alpha.8-2",
"@angular2-material/core": "^2.0.0-alpha.8-2",
"@angular2-material/icon": "^2.0.0-alpha.8-2",
"@angular2-material/radio": "^2.0.0-alpha.8-2",
"@angular2-material/slider": "^2.0.0-alpha.8-2",
"@angular2-material/tooltip": "^2.0.0-alpha.8-2",
"@types/google-maps": "3.1.28",
"angular-sample-module": "^0.1.2",
"angular2-highcharts": "^0.3.3",
"atob": "^2.0.3",
"autopulous-xdom": "^1.0.4",
"bootstrap": "^3.3.7",
"btoa": "^1.1.2",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"highcharts": "^5.0.0",
"jszip": "^3.1.3",
"ng2-bootstrap": "^1.1.16-9",
"primeng": "^1.0.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"xml2js": "0.4.17",
"xml2js-es6-promise": "1.1.1",
"zone.js": "^0.7.2" }, "devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/hammerjs": "^2.0.33",
"@types/jasmine": "2.5.38",
"@types/jszip": "0.0.31",
"@types/node": "^6.0.62",
"@types/pako": "^0.2.31",
"@types/xml2js": "0.0.32",
**"angular-cli": "1.0.0-beta.21",**
"angular-ide": "^0.9.10",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.0.2",
"typescript": "~2.0.3" }
}
我说这些问题出现在Angular CLI最新版本上。此外,定义HelloWorld模块的项目(库)不是使用Angular CLI构建的。我已根据以下示例创建了它: https://www.npmjs.com/package/angular-sample-module
然而,"不是NgModule"使用Angular CLI版本大于angular-cli@1.0.0-beta.21
时出现错误消息答案 3 :(得分:0)
我花了两天时间解决这个问题。添加
"angularCompilerOptions": {
"skipTemplateCodegen": true
}
到您的tsconfig.json
,它将创建所有必要的元数据文件。它对我有用。