Incorporating an external module into your Angular application for local use

I currently have two projects: my-components, which is an Angular library, and my-showcase, an Angular app. Whenever I make changes or add a new component to my library, I commit it to a private git repository and publish it to a private npm registry. This allows me to use the updated components in other applications like my-showcase. Before committing and publishing, I always ensure proper testing of the components. Up until now, I have been creating and developing new components directly within my my-showcase project. Once completed, the component is then moved to my-components.

Currently, I import my angular component library from npm as follows:

import {TimePickerModule} from '@company/components';

For testing and development purposes, I switch this to a local file path:

import {TimePickerModule} from '../../../../company-components/projects/components/src';

However, I encounter the following error message:

WARNING in ../company-components/node_modules/@angular/core/fesm5/core.js 15153:15-36
Critical dependency: the request of a dependency is an expression

And:

core.js:12584 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[DcStickyBitsDirective -> ElementRef]:
  StaticInjectorError(Platform: core)[DcStickyBitsDirective -> ElementRef]:
    NullInjectorError: No provider for ElementRef!

It seems that the component from the library used in the my-showcase app is referencing the wrong node_module folder from my-components (particularly @angular/core), instead of the node_module folder from my-showcase.

Is there a solution to this issue, or am I misunderstanding something about working with Angular Libraries and NPM? Please provide assistance if possible.

Answer №1

My solution involves modifying the tsconfig.json file by adding the following:

"@organization/components": [
    "../path/to/myComponents/src"
],

"@react/*": [
    "node_modules/@react/*"
]

However, I don't consider this workaround to be very elegant. It seems that the issue lies in Webpack grabbing Angular resources from the component library instead of the showcase project. This leads to incorrect path overrides.

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

Accessing JSON object from a URL via a web API using Angular 2 and TypeScript

`Hello, I am in need of some assistance in retrieving JSON data from a web API using Visual Studio 2015 .net Core, Angular 2 & Typescript. The Angular2 folders are located in /wwwroot/libs. Currently, I am utilizing Angular 2's http.get() method. Ho ...

Opt for a library exclusively designed for TypeScript

I am attempting to develop and utilize a TypeScript-only library without a "dist" folder containing compiled ".js" files. Here is the structure of my simple library: src/test/index.ts: export const test = 42; src/index.ts: import {test} from "./test"; ...

The 'google.maps' namespace does not export the 'MouseEvent' member after installing @agm/core and @types/google

When attempting to install @agm/core and @types/google maps, I encountered the following errors: node_modules/@angular/google-maps/map-polyline/map-polyline.d.ts:42:45 - error TS2694: Namespace 'google.maps' does not have an exp ...

What is the process for retrieving webpack environmental variables within a NativeScript application?

My task involves securely storing an environmental variable in webpack.config.js for Nativescript app bundling with webpack. The challenge is to maintain the secrecy of the environmental variable even after bundling. Is there a way to achieve this? I thi ...

Is it possible to manage NPM scope permissions within the Artifactory platform?

Artifactory enhances NPM functionality by allowing the creation of localized NPM registries. The common method for package management is utilizing NPM scope. Administrators of Artifactory can regulate who has publishing permissions to the registries. Ho ...

Utilizing MakeStyles from Material UI to add styling to a nested element

I was pondering the possibility of applying a style specifically to a child element using MakesStyles. For instance, in a typical HTML/CSS project: <div className="parent"> <h1>Title!</h1> </div> .parent h1 { color: # ...

"Error: Unable to locate module - 'electron-is-dev'" in my web development project using electron, typescript, and webpack

I'm currently working on a project using Electron, Typescript, and webpack. I am planning to integrate react.js into the project. However, when I ran "npx webpack" in the terminal, I encountered an error message. The error stated that the "electron- ...

How do you implement a conditional radio button in Angular 2?

I am facing an issue with two radio buttons functionality. When the first radio button is selected and the user clicks a button, the display should be set to false. On the other hand, when the second radio button is chosen and the button is clicked, ' ...

Absent 'dist' folder in Aurelia VS2015 TypeScript project structure

After downloading the Aurelia VS2015 skeleton for typescript, I encountered an issue trying to run the Aurelia Navigation app in IIS Express. One modification that was made to the skeleton was adding "webroot": "wwwroot" to the top level of project.json. ...

What other configurations are necessary to switch the default port of Angular from 4200 to a different number?

Currently, I am diving into the world of asp.net core webapi and angular 13 through Visual Studio Community 2022. The project setup involves two distinct projects built from these templates: Standalone TypeScript Angular Project Asp.Net Core Web API In ...

Angular material chips showcase a row of five chips

I am working with the basic mat-chips from angular material and I want to arrange them in rows of five without increasing their size: Chip1 Chip2 Chip3 Chip4 Chip5 ..................(space left) Chip6 Chip7 Chip8 Chip9 Chip10 ...............(space le ...

ag-grid provides unique filter options for custom date filtering in Angular 2

Currently, I am attempting to assign new options to a date column field by using the following method. However, these new options are not being displayed in the grid. let dateValues = ["equals", "inRange","quarter1","quarter2","quarter3","quarter4"]; { ...

issue with visibility of Angular Component

After following a straightforward YouTube tutorial for beginners on Angular, I encountered an issue. The tutorial covers how to use components, and even though I understand the concept well, the component simply does not appear no matter what I try. Here i ...

The essential library version GLIBC_2.28 could not be located

Encountered error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node) Every time I try to execute the command npm install or check the version using node -v, this error pops up. Any suggestions on how to resolve this ...

Obtain pictures from MongoDB for a website using Angular6

I'm currently in the process of developing my website and I want to showcase an image from my database on the header. Each customer is assigned a unique logo based on their ID, but I'm unsure how to use Angular to display it. Below is my code s ...

Passing parent HTML attributes to child components in Angular 2

Is there a way to pass HTML attributes directly from parent to child without creating variables in the parent's .ts class first? In the sample code below, I am trying to pass the "type=number" attribute from the parent to the app-field-label component ...

Troubden array filtration in Angular is malfunctioning

I recently developed an angular "filter component" intended to filter an array and display its contents. The keyword used to filter the array, value, is obtained from another component through a service. While the HTML displays both the value and the entir ...

The installation of `npm install [email protected] -g` command has encountered an error

After running the command npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9b7a9b499ecf7ecf7e8">[email protected]</a> -g to upgrade npm, it was successful. However, when I check the version using npm -v ...

What is the best way to merge multiple *ngifs in Angular?

Hey there, I am looking to create a conditional statement with three different outputs that will be displayed in a table. Currently, this is the code snippet I have: <td><div *ngIf="todo.diffDays >90">ninety</div> </td> I want ...

Using Sequelize to retrieve data from a relationship where a model belongs to another

Currently, I am developing an application that utilizes an existing MySQL database. Although I am able to successfully retrieve values from the tables, I encounter issues when trying to fetch data from associated models. The Purchase Order model: "use st ...