Is there a way to bring in a feature module from a personalized Angular library?

Just like in this particular inquiry, I crafted a unique Angular library (using Angular CLI 7.2.0) which consists of various feature modules:

MyLibraryModule
  FeatureModule1
    SomeComponent1
  FeatureModule2
    SomeComponent2

My goal is to selectively import only one feature module into my main application, similar to how Angular Material modules are imported (

import { MatButtonModule } from '@angular/material';
):

import { FeatureModule1 } from 'my-library';
...
@NgModule({
  imports: [
    ...,
    FeatureModule1,
  ]
})
...

This approach leads to the following error (while building the main project):

ERROR in : Unexpected value 'FeatureModule1 in ./node_modules/my-library/my-library.d.ts'
imported by the module 'AppModule in ./src/app/app.module.ts'.
Please add a @NgModule annotation.

However, when I directly import the library module (

import { MyLibraryModule } from 'my-library';
) into my primary application, everything functions smoothly.

The structure of my-library.module.ts appears as follows:

import { NgModule } from '@angular/core';

import { FeatureModule1 } from './feature-module-1/feature-module-1.module';
import { FeatureModule2 } from './feature-module-2/feature-module-2.module';

@NgModule({
  imports: [ FeatureModule1, FeatureModule2 ],
  exports: [ FeatureModule1, FeatureModule2 ],
})
export class MyLibraryModule{ }

The public_api.ts file handles the export of all modules.

I suspect that the issue lies within the packaging process, as this setup works flawlessly in my testing project located in the same directory as the library.

Attempts to align the building process with that of @angular/material have been made, although it seems they follow a slightly different approach compared to the official methods.

Answer №1

The issue arose because I was utilizing barrel files within my feature modules (index.ts) and importing them in my public_api.ts in this manner:

import * from './feature-module-1';

However, as mentioned here, it is necessary to directly reference the barrel file. Otherwise, the .d.ts file for the package will not include all exports. Therefore, correcting the import line in my public_api.ts resolved the issue:

import * from './feature-module-1/index';

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

Is there a way to incorporate an SSL certificate into a JavaScript POST request?

I need to send a post request to an endpoint using a SSL certificate in either typescript or javascript. This is for a project that I am currently working on with Ionic 3. ...

Utilize DomSanitizer to add custom styles to elements using classes in Angular

<div [innerHtml]="someHtml | safeHtml"></div> someHtml = '<span class="fas fa-calendar" style="font-size:15px"></span>' By utilizing the innerHtml property, I am able to inject a html element and apply inline styles thro ...

Difficulties arise when attempting to install nodejs on linux using the npm install nodejs command

While attempting to execute... npm install nodejs I encounter the subsequent issue: npm WARN optional Skipping failed optional dependency /chokidar/fsevents: npm WARN notsup Not compatible with your operating system or architecture: [email prot ...

Unable to fetch options for drop-down list from Database

As someone who is new to frontend application development, I am facing a challenge in populating a Select list from the database. Despite following similar approaches like the one discussed in How to populate select dropdown elements with data from API - R ...

``The positioning of the element does not seem to be effective with the selected [

I'm struggling to position a div using [style]. Even after following the advice from various sources, I can't seem to place the div correctly at 100,100. Could someone please review the code snippet below and point out any errors? Check out the ...

React-bootstrap-table Axios delete operation causing [object%20Object] to be displayed in the browser console

I am having trouble executing a delete operation using axios on a react-bootstrap-table, and encountering this error in the console DELETE http://localhost:9000/api/terminals/[object%20Object] Uncaught (in promise) Error: Request failed with status cod ...

The error in the FormGroup is not being cleared by the Reactive Form Async Validator

Working on a web application in Angular 10, I have created a simple form to validate two values on the backend using an async validator. The async validator functions correctly as it should. The Issue: Despite a successful HTTP call, the error is not comp ...

The Google OAuth profile response is lacking the Profile ID - NextAuth

I've been diving into a helpful tutorial on implementing roles in the next-auth session. However, I've encountered an issue where adding the profile property results in unexpected behavior with the profile being undefined. Additionally, there are ...

Best practice in Angular 4: utilize services to load and store global data efficiently

I would like to create an angular 4 application that allows me to search for a user in a database and use their information across different routes. The issue I am facing currently is that when I load data via a service, change the route, and then return, ...

What should the expected response be from Angular service observables in cases where an object cannot be found?

I recently encountered a perplexing architectural dilemma involving the utilization of rxjs and observables when engaging with a data service in Angular. Consider the following scenario: displayDetails(id: String): void { this._dataService.getById(id). ...

Expanding a generic class by introducing a new generic parameter

I have a basic framework class: export class BaseClass< A extends boolean = false, B extends boolean = false, > { readonly fieldA: A; readonly fieldB: B; constructor(options: { readonly?: A, many?: B } = {}) { // @ts-ignor ...

Encountered difficulty locating the module path 'stream/promises'

When importing the following in a typescript nodejs app import { pipeline } from "stream/promises"; Visual Studio Code (vscode) / eslint is showing an error message Unable to resolve path to module 'stream/promises' https://i.sstatic. ...

Issue: Module '@nrwl/workspace/src/utilities/perf-logging' not found

I attempted to run an Angular project using nxMonorepo and made sure to install all the necessary node modules. However, when I tried running the command "nx migrate --run-migrations" in my directory PS C:\Users\Dell\Desktop\MEANAPP&bso ...

"Enhance your user experience with seamless drag and drop functionality for transferring items between

I am currently working on transferring items between a list and table using the drag-and-drop feature of PrimeNG. Both elements should be able to act as both drag sources and drop destinations. My project is based on PrimeNG-9.0.0 and Angular 9.0.2 https ...

React Native is throwing an error message saying that the Component cannot be used as a JSX component. It mentions that the Type '{}' is not assignable to type 'ReactNode'

Recently, I initiated a new project and encountered errors while working with various packages such as React Native Reanimated and React Navigation Stack. Below is my package.json configuration: { "name": "foodmatch", "version ...

Is it possible to render dynamic components based on the input property of the parent?

Essentially, I have a top-level component called "Pageview" that showcases various instances of a specific component being utilized. The component being displayed can be changed by providing a route input property to the Pageview component. My goal is to s ...

Creating an RxJS observable stream from an event emitted by a child element in an Angular 2 component template

Currently incorporating Angular 2.0.0-rc.4 alongside RxJS 5.0.0-beta.6. In the midst of exploring various methods for generating observable streams from events, I find myself inundated with choices and would like to gather opinions. Recognizing that there ...

The ValidationPipe does not function properly when utilizing app.useGlobalPipes

Hello! I'm looking to implement the ValidationPipe globally using useGlobalPipes. Currently, my code looks like this: import 'dotenv/config'; import {NestFactory} from '@nestjs/core'; import {ValidationPipe} from '@nestjs/com ...

Is there a way to imitate a method that initiates an AJAX request?

I am currently working on writing tests for my Angular application and I need to mock a method in order to avoid making actual requests to the server. Within my grid.service.ts file, here is the method I am trying to mock: loadAccountListPromise(id: str ...

Utilizing the "as" keyword for type assertion in a freshly created react application using create-react-app leads to the error message `Parsing error: Unexpected token, expected ";"`

After creating a new CRA project using yarn create react-app my-app --template typescript, I encountered an error when trying to run the development server with yarn start: src/App.tsx Line 5:24: Parsing error: Unexpected token, expected ";" ...