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

Bringing in a Vue.js component without relying on npm installation or webpack

I'm currently working on integrating this particular component into my project: https://www.npmjs.com/package/vuejs-auto-complete The issue I've encountered is that the restriction against using npm install has posed a challenge. As our project ...

Having trouble with my Angular subscription - not behaving as I anticipated

I am facing an issue on my shop page where I have a FilterBarComponent as a child component. On initialization, I want it to emit all the categories so that all products are rendered by default. However, on my HomePageComponent, there is a button that allo ...

Evaluation of button display based on certain conditions

I currently have two different render functions that display certain elements based on specific conditions. The first render function looks like this: private render(): JSX.Element { return ( <div> {this.props.x && this.state.y ...

Creating a dynamic web application using Asp .NET Web Api, MVC, and Angular 2, integrating an action that

Working on an ASP .NET MVC application integrated with Angular 2, I encountered a problem when trying to communicate from the angular service to a WebApi Controller. The issue arises when attempting to access an action within the WebApi Controller that req ...

Uh-oh! Angular 6 has encountered an unexpected error with template parsing

I am currently working on an Angular application where I have integrated the FormsModule from '@angular/forms' in my app.module.ts. However, despite this, I keep encountering the error message No provider for ControlContainer. Error log: Uncaug ...

Expanding and shrinking div elements in Angular with sliding effects on other divs

Hello, I am just starting with angular and angular animations, and I have encountered a problem. Here is the html code that I am working with: <div class="main"> <div class="left" *ngIf="showLeftSide" [@slideInOutLeft]></div> <di ...

How come the variable `T` has been assigned two distinct types?

Consider the following code snippet: function test<T extends unknown[]>(source: [...T], b: T) { return b; } const arg = [1, 'hello', { a: 1 }] const res = test(arg, []) const res1 = test([1, 'hello', { a: 1 }], []) The variabl ...

The Npm redis client fails to retrieve a key when making a GET request on an express route within a Node.js application

Quick Query Although Redis seems to be functioning well, I am facing difficulties with the redis client.get() function within a Node.js application. Pertinent Particulars My NodeJS server.js script is concise: 'use strict'; const express = req ...

The system is unable to process the property 'items' due to a null value

When trying to access the properties of ShoppingCart, an error is encountered stating that Property item does not exist on type {}. The mistake made in the code is unclear and difficult to identify. shopping-cart.ts import { ShoppingCartItem } from &apos ...

Managing Observable<Person[]> in ng-bootstrap typeahead instead of Observable<string[]>: a complete guide

I'm new to Angular/Typescript and have a question. I recently tried out the example from Wikipedia in ng-bootstrap typeahead. Instead of using the Wikipedia call, I decided to use a custom REST service that has the following GET endpoint: GET /pers ...

What are the best steps to follow when creating a new package within a lerna monorepo?

I have recently come into possession of a monorepo that contains a packages folder housing all the current packages. My goal is to include a new main package that is essential for my existing panel package, which is currently at version 0.34.0. Since I fre ...

Exploiting the Power of useRef with TypeScript in Functional Components of React

I'm having trouble accessing the child component method from the parent component using useRef. Eventually, the SayHi method will be responsible for updating the hook state in the child component. Unfortunately, I am encountering some bugs that I can ...

Utilizing the Route.post() method in Node.js

I'm currently developing a Node.js application and I'm facing an issue while trying to access functions from my index.js file in the calls.js controller. Every time I include var IndexBot = require('/root/afstudeerwerk/chatbotPIROS/index&ap ...

Unable to employ the inequality operator while querying a collection in AngularFire

I'm facing a challenge with pulling a collection from Firebase that is not linked to the user. While I've managed to query the user's collection successfully, I am struggling to retrieve the collection that does not belong to the user using ...

How to manipulate dates using Angular 2's date pipe to add or subtract hours

I am encountering an issue with the new Angular 2 Date Pipe. My date value is as follows: let myDate = '2017-01-31T17:53:36' When I use the Date Pipe to format it in the view like this; {{myDate | date: 'dd/MM/yyyy HH:mm' }} It dis ...

Manufacturing TypeScript classes that are returned by a factory

Developed a custom library that generates classes based on input data and integrates them into a main class. To enhance code maintainability and readability, the logic for generating classes has been extracted into a separate file that exports a factory f ...

The command you entered could not be found: Expression not recognized

After successfully installing ExpressJS on my OSX using sudo npm install express-generator -g I encountered the following error: -bash: express: command not found During installation, I received this output: /Users/myusername/.node/bin/express -> / ...

I encountered an issue where I could not successfully update a list pushed into an array using the push function. Despite attempting to update the list, I

export class ApproveComponent implements OnInit { @Output() public next: EventEmitter<any> = new EventEmitter<any>(); codes: any[] = []; selectedCode: any; this.Apiservice.komm.subscribe(data => { this.se ...

Dependency mismatch in main package.json and sub package.json

Imagine you have a project structure in Typescript set up as follows: root/ api/ package.json web/ package.json ... package.json In the main package.json file located in the root directory, Typescript is installed as a dependency to make ...

The module named "jquery" has not been loaded in this context: _. Please use require() to load it

As I work on migrating my Javascript files to Typescript, I encountered an issue when trying to use the transpiled javascript file in an HTML page. The error message I received is as follows: https://requirejs.org/docs/errors.html#notloaded at makeError (r ...