问题
I created a library in order to share some components between two different projects, using ng-packagr module.
The structure of the lib is
In my library
The src/package.json :
{
"name": "my-ng-library",
"version": "0.0.0",
"license": "MIT",
"ngPackage": {
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "index.ts"
},
"dest": "../dist"
},
"private": false,
"dependencies": {},
"peerDependencies": {
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/router": "^5.2.0",
"@angular/common": "^5.2.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19",
"compass-mixins": "^0.12.10"
}
}
src/components/banner/banner.module.ts:
import { BannerComponent } from './banner.component';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
imports: [CommonModule],
declarations: [BannerComponent],
exports: [BannerComponent],
providers: []
})
export class BannerModule { }
src/index.ts:
export { BannerModule } from './components/banner/banner.module';
export { BannerComponent } from './components/banner/banner.component';
In the client app
app.module.ts:
import { BannerModule } from 'my-ng-library/dist';
@NgModule({
declarations:[
BannerComponent
],
imports: [
BannerModule
]
})
Everything is working fine, serving the app in local, but when I try to build for prod I get the following error:
ERROR in : Unexpected value 'BannerModule in /Users/username/Dev/Work/app-mobile-network-site/node_modules/my-ng-library/dist/components/banner/banner.module.d.ts' imported by the module 'AppModule in /Users/username/Dev/Work/Essence/app-mobile-network-site/src/app/app.module.ts'. Please add a @NgModule annotation.
来源:https://stackoverflow.com/questions/50988187/angular-error-while-building-because-external-library-unexpected-value-banner