Unveiling individual modules of an Angular library using public-api.ts in the latest version of Angular (Angular 13)

After completing an upgrade on my Angular library project from version 11 to 13, I encountered an issue when attempting to execute the ng build command.

In version 11, the setup looked like this:

  • I had multiple smaller modules, each containing various components and directives
  • each module was made accessible through the public-api.ts
  • the consumer interface could import each module as needed

Therefore, each module structure was quite straightforward:

@NgModule({
  declarations: [AComponent],
  imports: [],
  exports: [AComponent],
})
export class AModule {}
@NgModule({
  declarations: [BComponent],
  imports: [],
  exports: [BComponent],
})
export class BModule {}

And then exposed in public-api.ts:

export { AModule } from './lib/acomponent/a.module';
export { BModule } from './lib/bcomponent/b.module';

This system worked smoothly with Angular 11 using ngcc for library building. However, upon upgrading to Angular 13 (where libraries are compiled with Ivy partial compilation mode by default), issues arose with the aforementioned modules:

error Unsupported private class AComponent. This class is visible to consumers via AModule -> AComponent, but is not exported from the top-level library entry point.

error Unsupported private class BComponent. This class is visible to consumers via BModule -> BComponent, but is not exported from the top-level library entry point.

So how should modules be properly exposed in an Angular library?

Answer №1

Make sure to properly export all components in your public API:

export { AModule } from './lib/acomponent/a.module';
export { AComponent } from './lib/acomponent/a.component';
export { BModule } from './lib/bcomponent/b.module';
export { BComponent } from './lib/bcomponent/b.component';

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create a distinct style for material inputs without relying on ng-deep, !important declarations

I am looking to customize the appearance of a material input by making it round with border radius. I found a solution that involves adding a class "custom-search" to the mat-form-field and applying the necessary styles in the global stylesheet: .custom-se ...

Troubleshooting the ngx-image-zoom dependency error: How to resolve the unresolved dependency issue

When working on an angular project in version 10, I encountered challenges while installing the ngx-image-zoom component due to dependencies with angular 10. Despite this, I managed to resolve the issues. However, in my current project using angular 11, I ...

Creating a personalized HTML email template with a TypeScript foreach loop

As I work on developing an app, users will have the opportunity to share product information via email. Each product includes a title, image, description, ingredients, and a list of energy values. Currently, I am able to send an email with all the product ...

NestJS is having trouble importing generated types from the Prisma client

When working with Prisma in conjunction with NestJs, I encountered an issue after defining my model and generating it using npx prisma generate. Upon importing the generated type, I can easily infer its structure: import { FulfilmentReport, FulfilmentRepor ...

(angular 8) Error occurred when converting a file or image to FormData due to an invalid value (Note: FormData object printed as Object Form{})

I encountered an issue where I am getting an invalid value from form data. The value appears correct in `this.fileData` with a size of 5701, but becomes empty when converted to form data - `{}` is logged when I console.log the form data. Additionally, acce ...

Issue encountered with express-jwt and express-graphql: TypeScript error TS2339 - The 'user' property is not found on the 'Request' type

Implementing express-jwt and graphql together in typescript has been a challenge for me. import * as express from 'express' import * as expressGraphql from 'express-graphql' import * as expressJwt from 'express-jwt' import s ...

Allusion to a intricate data component

In my code, I have a model that is being represented by a class. For example, let's consider the model of a car: export class Car { public name : string; public color: string; public power : number; public service : boolean; } All c ...

Issue with mssql.connect await causing timeout in Jest

Testing some functionality in a nextjs Typescript project that needs to interact with the database directly, not relying on mocked sql query results. But encountering issues with it actually writing to the database. A brief example of the problem: /* @/li ...

Fast + Vue3 + VueRouter Lazy Load Routes According to Files

I am currently working on implementing Domain-Driven Design (DDD) to Vue, and the project structure looks like this: src - App - ... - router - index.ts - Dashboard - ... - router - index.ts - ... The goal is for src/App/router/index.ts to ...

Tips for addressing the error "Ensure each child in a list has a distinctive 'key' prop" in a React function using TypeScript

Encountered the following warning: Warning: Each child in a list should have a unique "key" prop. Inspect the render method of TabContext. Refer to https://reactjs.org/link/warning-keys for more details. in TabForGroupInList (at Product.tsx:148) ...

Angular always ensures that the Ionic4 type homepage is consistently loaded

My Ionic4 App seems to consistently load the homepage despite my efforts to set different initializations such as loadChildren, component, and redirectTo. The issue persists with always loading the homepage. .app-routing.module.ts const routes: Routes = ...

Invoke a method in an Angular 2 component using an HTML event

Can an angular component method be invoked using an HTML event? <shape onclick="myMethodInParentComponent()" > I am unable to use (click) as shape is not recognized by Angular. Shape also contains several unknown sub elements making it impractical ...

Angular 2 Error: Unable to access the `subscribe` property of an undefined value

In my Angular 2 project, I have a single form that serves the purpose of adding a new event or editing an existing one. The logic checks the URL parameter to determine whether an ID is present. If an ID is found, it subscribes to the editEvent method from ...

Executing several asynchronous functions in Angular 2

I am currently developing a mobile app and focusing on authentication. In order to display data to the user on my home page, I need to connect to various endpoints on an API that I have created. Although all endpoints return the correct data when tested i ...

Issue with type narrowing and `Extract` helper unexpectedly causing type error in a generic type interaction

I can't seem to figure out the issue at hand. There is a straightforward tagged union in my code: type MyUnion = | { tag: "Foo"; field: string; } | { tag: "Bar"; } | null; Now, there's this generic function tha ...

What exactly does Isomorphic rendering entail when it comes to ReactJS?

Javascript frameworks pose a challenge for Search Engine optimization as they create dynamic content that is not easily indexed. React addresses this issue with Isomorphic rendering. But what exactly does this concept entail and how does it differ from Ang ...

How to Showcase Images in an Ionic 2 App Using HTML Content

This amazing app was built with Ionic 2 technology. It leverages a REST API to retrieve data in JSON format. Interestingly, one of the fields sent from the server is HTML content. <div [innerHTML]="'<p>' + eventMoreDetails.DescriptionHt ...

Running tests on functions that are asynchronous is ineffective

Recently, I made the switch from Java to TypeScript and encountered a challenging problem that has been occupying my time for hours. Here is the schema that I am working with: const userSchema = new Schema({ username : { type: String, required: true }, pa ...

Typescript counterpart of a collection of key-value pairs with string keys and string values

Within the API I'm currently working with, the response utilizes a data type of List<KeyValuePair<string, string>> in C#. The structure appears as shown below: "MetaData": [ { "key": "Name", &q ...

Sinon fails to mock the provided URL when GET request includes parameters

I am currently working on creating test cases for the services in my Angular application and encountering some challenges. Below is the code snippet for the service: /** * Sends http request to fetch client states and territories available for a specifi ...