这个类对于使用者来说是可见的,但是不能从顶级库入口点导出

我升级所有的角度库到 angular 9.0.0使用 ng update和当我试图建立他们我得到以下错误。

错误:

不支持的私有类 Some Component。这个类对于使用者来说是可见的,但是不能从顶级库入口点导出。

有人解决了这个错误吗?

41882 次浏览

This error happens if any component is exported in NgModuleand not included in your public_api.ts, Angular 9 will throw an error now.

This error was not coming in Angular 8 but after upgrading to Angular 9 it started showing.

If you exported any service, module or component, etc in NgModule make sure to include them in public_api.ts or else angular 9 will throw error now.

Fix: add your component to the public_api.ts

export * from './lib/components/some-me/some-me.component';

I was struggling with the same issue today.

My prerequisites:

  • I work on an Angular 11 library type project;
  • I have added a new directive;
  • I got an error as above when tried to add my directive to module exports.

Fix:

  • I have added file export to index.ts file:

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

This error happened to me because I used the default keyword to export my component :

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

The use of this keyword was suggested by my Linter and allows to write imports as import FormComponent from './form.component'; instead of import { FormComponent } from './form.component';

However this does not seem to work well along public-api.ts. The solution for me was to remove the default keyword and change all imports.

I ran into the same issue. I couldn't remove the default keyword, as Storybook required me to have that. I ended up fixing it by changing this:

export * from './lib/components/some-me/some-me.component';

... to this:

export { default as SomeComponent } from './lib/components/some-me/some-me.component';

in the public_api.ts file.