Javascript 构建时的角度错误,因为外部库-意外值“;BannerModule…“;
我使用ng packagr模块创建了一个库,以便在两个不同的项目之间共享一些组件 库的结构是 在我的库中 src/package.json:Javascript 构建时的角度错误,因为外部库-意外值“;BannerModule…“;,javascript,angular,angular5,ng-packagr,angular-library,Javascript,Angular,Angular5,Ng Packagr,Angular Library,我使用ng packagr模块创建了一个库,以便在两个不同的项目之间共享一些组件 库的结构是 在我的库中 src/package.json: { "name": "my-ng-library", "version": "0.0.0", "license": "MIT", "ngPackage": { "$schema": "./node_modules/ng-packagr/ng-package.schema.json", "lib": { "ent
{
"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 { }
import { BannerModule } from 'my-ng-library/dist';
@NgModule({
declarations:[
BannerComponent
],
imports: [
BannerModule
]
})
src/index.ts:
export { BannerModule } from './components/banner/banner.module';
export { BannerComponent } from './components/banner/banner.component';
在客户端应用程序中
app.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 { }
import { BannerModule } from 'my-ng-library/dist';
@NgModule({
declarations:[
BannerComponent
],
imports: [
BannerModule
]
})
一切正常,在本地为应用程序提供服务,但当我尝试为prod构建时,出现以下错误:
错误:模块“AppModule in/Users/username/Dev/Work/app mobile network site/node_modules/my ng library/dist/components/banner/banner.module.d.ts”导入了意外值“BannerModule in/Users/username/Dev/Work/essention/app mobile network site/src/app/app.module.ts”。请添加@NgModule注释
您是否尝试过运行npm安装?可能您在node_modules文件夹中缺少文件。您的应用程序中的
“@angular/core”
版本是什么?@NishantGhodke 5.2(lib和app)@FunkRehkitz是的,当然,我可以在本地轻松运行应用程序,但我无法为生产构建它。我在angular 6.0.8中遇到了几乎相同的问题: