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

Tips for dealing with strong reference cycles in TypeScript?

I have created a tree-like structure in my implementation, consisting of parent and child objects. The parents contain a list of children while the children have references to their parents, facilitating easy navigation through the tree. I am now contempla ...

Merging objects with identical keys into a single object within an array using Typescript

Here is the array that I am working with: Arr = [{ code: "code1", id: "14", count: 24}, {code: "code1", id: "14", count: 37}] My objective is to consolidate this into a new array like so: Arr = [{ code: "code1& ...

Retrieve the instance from the provider using its unique key without needing to inject its dependencies

I created a custom class called PermissionManager, which takes a list of Voter interfaces as an input in its constructor. export interface Voter { vote(): bool; } export class PermissionManager { constructor(private readonly ...

*ngFor not functioning properly within Angular ionic modal

While working on my Ionic application with Angular, I encountered an issue with the ngForm not functioning properly inside a modal. I have tried to identify the problem with a simple code snippet: <li *ngFor="let item of [1,2,3,4,5]; let i = index ...

The Angular application has been successfully deployed on a Tomcat server as a war

I am planning to deploy a single page application (SPA) developed in Angular, along with various static files like *.css, .js, /assets/, all packed inside a war file on Tomcat. The issue I am facing is that whenever a user enters a path that does not corr ...

Issue with Angular 2: Not receiving events when subscribing to a service's Subject property

Presented below is a service: @Injectable() export class AuthService { public reset: Subject<any>; constructor() { this.reset = new Subject(); } public logout() { this.reset.next('logout'); } } Here is an additional s ...

Tips for resolving Typescript type error when overriding MuiContainer classes

My application is divided into two main files: (https://codesandbox.io/s/react-ts-muicontainer-override-yywh2) //index.tsx import * as React from "react"; import { render } from "react-dom"; import { MuiThemeProvider } from "@material-ui/core/styles"; imp ...

What is the procedure for linking my SQL database with Angular?

This is a sample HTML code snippet to create a sign-in form: <div class="col-md-8"> <form (submit)="onSubmit()" method="POST"> <input type="text" class="form-control mb-2" name="names" [(ngModel)]="profileForm.name" placeholder="Usern ...

Display the left and right arrows on a Vuetify Slide Group Component card only when hovered

How can I modify the Vuetify Slide Group Component to make left and right arrows appear on the card instead of taking up extra space? I am attempting to customize the CSS for this. Any suggestions? <v-slide-group show-arrows class="my-3 slide-gro ...

Integrating information from various sources to create a cohesive online platform

I am looking to incorporate data from various sources into a single web page: Social networks (Facebook, Twitter, LinkedIn, etc.) RSS feeds Article meta tags (particularly OpenGraph and Twitter cards) This data may change dynamically based on user inter ...

The Mat table is not updating on its own

I am facing an issue in my Angular application where a component fetches a hardcoded list from a service and subscribes to an observable to update the list dynamically. The problem arises when I delete an element from the list, as it does not automaticall ...

I aim to toggle the visibility of input fields upon clicking a button

Form.html <form [formGroup]="myForm"> <ion-button [(ngModel)]="isActive"(click)="onClick()" >Add</ion-button> <ion-item> <ion-label position="floating">First Name</ion-label&g ...

Implementing dynamic background images in Angular 4 using div placeholders

Is there a way to include a placeholder or default image while waiting for item.imgSrc to load on the screen? <div class="style" *ngFor="let item of array; <div [style.backgroundImage]="url('+ item.imgSrc +')" class="image">< ...

Incorporating observables into an existing axios post request

Currently, I have an API using axios to send HTTP POST requests. These requests contain logs that are stored in a file. The entire log is sent at once when a user signs into the system. Now, I've been instructed to modify the code by incorporating Rx ...

Is it necessary for an Angular service's query method to return an error when it doesn't find any

Let's say I create a service that includes a method called getProducts When using this service, it looks something like this this.service.getProducts('someProduct').subscribe(product => {}, err => {}); If the product with the name & ...

send image back to Angular component from server response

I'm extremely close to achieving my goal. The server is successfully returning the image and sending it in the response. Now, the challenge lies in getting my angular component to properly display it. Let me share what I have done so far: Firstly, h ...

Guide on setting up a route in Next.js

Recently, I developed a simple feature that enables users to switch between languages on a webpage by adding the language code directly after the URL - i18n-next. Here's a snippet of how it functions: const [languages, ] = React.useState([{ langua ...

Retrieve the encrypted URL

I'm facing an issue with extracting parameters from an encrypted URL. When using the queryparams function, it only retrieves a portion of the URL after being decrypted. For instance, consider this example URL: http://localhost:4200/househouse? MGRjYjQ ...

Enhance your TypeScript React development with NeoVim

As a newcomer to vim, I decided to test my configuration with react and typescript. To do this, I created a simple demo app using the command npx create-react-app demo --template typescript. Next, I opened the directory in neovim by running nvim .. However ...

Using Angular 5 with Typescript to generate and return an array of freshly instantiated typed objects

My backend service provides me with "moments," and I have two functions to handle this data. One is a get() method that returns a single object, and the other is a search() method that returns an array of objects. moment.service.ts The get method success ...