72

我将我所有的角度库都升级为angular 9.0.0使用ng update,当我尝试构建它们时,我得到了以下错误。

错误:

不支持的私有类 SomeComponent。此类通过 SomeModule -> SomeComponent 对消费者可见,但不会从顶级库入口点导出。

有人解决了这个错误吗?

4

3 回答 3

156

如果任何组件被导出NgModule但未包含在您的 中public_api.ts,则会发生此错误,Angular 9现在将引发错误。

这个错误没有出现,Angular 8但在升级到Angular 9它之后开始显示。

如果您导出了任何service,modulecomponent, 等,请NgModule确保将它们包括在内,public_api.ts否则angular 9现在会抛出错误。

修复:将您的组件添加到public_api.ts

export * from './lib/components/some-me/some-me.component';
于 2020-02-07T22:42:18.597 回答
5

我今天在同样的问题上苦苦挣扎。

我的先决条件:

  • 我从事 Angular 11 库类型项目;
  • 我添加了一个新指令;
  • 尝试将我的指令添加到模块导出时,出现上述错误。

使固定:

  • 我已将文件导出添加到 index.ts 文件:

export * from './just/a/relative/path/to/the/directive/{{myDirectiveFile}}';

于 2021-04-06T14:40:07.083 回答
0

这个错误发生在我身上,因为我使用default关键字导出我的组件:

@Component({
  selector: 'lib-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.scss'],
})
export default class FormComponent implements OnInit {
    // ...
}

我的 Linter 建议使用这个关键字,并允许将导入写为import FormComponent from './form.component';而不是import { FormComponent } from './form.component';

然而,这似乎并不奏效public-api.ts。我的解决方案是删除default关键字并更改所有导入。

于 2021-07-07T08:04:38.653 回答