This class is visible to consumers via SomeModule -> SomeComponent, but is not exported from the top-level library entrypoint

AngularAngular LibraryAngular9

Angular Problem Overview


I upgraded all my angular library to angular 9.0.0 using ng update and when I try to build them I got below error.

Error:

> Unsupported private class SomeComponent. This class is visible to consumers via SomeModule -> SomeComponent, but is not exported from the top-level library entrypoint.

Anyone solved this error?

Angular Solutions


Solution 1 - Angular

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';

Solution 2 - Angular

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}}';

Solution 3 - Angular

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAniruddha DasView Question on Stackoverflow
Solution 1 - AngularAniruddha DasView Answer on Stackoverflow
Solution 2 - AngularViktoriia ShchutskaView Answer on Stackoverflow
Solution 3 - AngularjprissiView Answer on Stackoverflow