首页 > 解决方案 > 目标入口点中的错误缺少依赖项:对于子组件

问题描述

我有一个带有子组件 child-x 和 child-y 的 angular 8 库 lib-a。

在使用 angular 9 项目中的 lib-a 时,出现如下构建错误:

**目标入口点“@abc/lib-a”中的错误缺少依赖项:

ng-package.json 是,

{
  "$schema": "../../node_modules/ng-package/ng-package.schema.json",
  "dest": "../../dist/lib-a",
  "lib": {
    "entryFile": "src/public-api.ts"
  }
}

lib-a 的 package.json 是:

{
  "name": "lib-a",
  "version": "1.0.6",
  "description": "lib a",
  "peerDependencies": {
    "@angular/common": "^8.0.0",
    "@angular/core": "^8.0.0",
    "@angular/elements": "^9.1.6",
    "@angular/cdk": "^8.2.3"
  }
}

编辑:public-api.ts

export * from './lib-a/lib-a.module';
export * from './lib-a/child-x/child-x.component';
export * from './lib-a/child-y/child-y.component';

我尝试通过在 public-api.ts 入口点添加组件来修复,但这不起作用。

我搜索了网络,但没有找到与此子组件相关的问题的答案。

标签: angularangular9angular-library

解决方案


这个问题突然出现在我面前,我能够解决它。我的项目文件夹中有一个角度库和应用程序。我正在玩弄使用引用库的导入,而不是组件的绝对路径,即import {mycomponent} from 'my-library'而不是 import {mycomponent} from 'projects/src/lib/<etc>'. 指向 dist 文件夹的代码挥之不去。一旦我删除了 dist 文件夹,就会显示真正的错误(这些引用)。一旦我修复了这些错误,问题就解决了。


推荐阅读