Troubleshooting problems with connecting two Angular projects using Npm

For a while now, I've been facing a challenge when working on an Angular project that utilizes npm link with a library that has its own node modules folder. Each project needs its own set of node modules because they both have their own components and the consumer will need to import the library project module.

Let's say I have a ConsumerProject linked to a LibraryProject. Here's what I run in the command line: In the root directory of LibraryProject

npm link 

In the root directory of ConsumerProject

npm link library-project

Both projects have the same dependencies/devDependencies:

"dependencies": {

"@angular/animations": "^4.2.4",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"core-js": "^2.4.1",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"

}, "devDependencies": {

"@angular/cli": "1.3.2",
"@angular/compiler-cli": "^4.2.4",
"@angular/language-service": "^4.2.4",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "~3.1.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.3.2",
"typescript": "~2.3.3"

}

The ConsumerProject imports the LibraryModule from the LibraryProject. When I run ng serve in the ConsumerProject, I encounter the following errors:

ERROR in Error encountered resolving symbol values statically. Function 
calls are not supported. Consider replacing the function or lambda with a 
reference to an exported function (position 194:50 in the original .ts 
file), resolving symbol NgModule in *path to directory*, resolving symbol 
LibraryModule in *path to directory*, resolving symbol LibraryModule in 
*path to directory*

Recompiling the code resolves this error, but upon loading the page, I get the following error: Uncaught Error: Unexpected value 'LibraryModule' imported by the module 'AppModule'. Please add a @NgModule annotation.

I did some research on this issue and found that if the installed angular/cli package is version 1.2.7 or below, you can add the following code to your tsconfig.json file to run the project successfully:

"path": {
  "@angular/*": [
    "../node_modules/@angular/*"
  ]
}

This assumes that your baseUrl is in your src directory. However, using this with cli 1.3.0 does not solve the problem anymore. As a temporary solution, I've been deleting the node modules folder in my library until I need it. But ideally, there should be a proper fix for the issue instead of constantly uninstalling and reinstalling the node modules folder.

Answer №1

One solution we've found is to utilize the following steps:

cd library-project\dist 
npm pack

Then, in the main module, run:

npm i \path\to\library-project\dist\somelibrary.tgz

Hopefully this helps!

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

Retrieving data from array services in Angular using Typescript

I need help retrieving data from an array in my services using a get function. I've tried using the .filter and .find functions, but I'm struggling with the execution and haven't been able to retrieve the data successfully. I know this may b ...

String validation using regular expressions

Below is the code I am using to validate a string using regular expressions (RegEx): if(!this.validate(this.form.get('Id').value)) { this.showErrorStatus('Enter valid ID'); return; } validate(id) { var patt = new RegExp("^[a-zA- ...

Generate a vector tile in Azure Maps containing a massive one million data points

Is it possible to use Azure maps to display a large amount of data points, such as one million? I am interested in creating an Azure map with optimized performance and loading it into my Angular application using a map URL. Can you provide guidance on how ...

Is there a forEach loop supported in Angular2? If so, why does it display all objects with the same value?

Hello everyone, I'm currently facing an issue with getting server response objects and passing them into a new Array object. In the code snippet below, you can see that when I try to print these newly passed objects using a forEach loop, they appear a ...

Creating a tailored regular expression for validating email addresses

Up to this point, I have crafted a regex pattern as Pattern="^(?=.*[a-zA-Z].*)([a-zA-Z0-9._%+-]+@([a-zA-Z0-9-]+[a-zA-Z0-9-]+(\.([a-zA-Z0-9-]+[a-zA-Z0-9-])+)?){1,4})$" that meets the following criteria: Not all characters should be numbers, ...

What is the process of creating an asynchronous function that will resolve a promise when the readline on('close') event is triggered within it in Typescript?

Here's a code snippet I'm working with: private readFile() { var innerPackageMap = new Map<string, DescriptorModel>(); // Start reading file. let rl = readline.createInterface({ input: fs.createReadStream(MY_INPUT_FILE ...

Configuring the array interval in an Angular application

I'm facing an issue while attempting to use the setInterval() function to update text for the user every 3 seconds. My attempt at looping with a for loop has not been successful - I only see 'test 03' and nothing else. I'm struggling ...

Using dynamic parameters in React Router v4

Looking to implement dynamic routing in my React app using React-Router v4. I am aiming to construct the following address: http://localhost:7777/oceanside-yaht-club/booking/search where oceanside-yaht-club can change based on the customer. However, my ...

What is the best way to make the first option blank?

Is there a way to have the select field start with an empty value instead of the default dollar sign? The demonstration can be found at https://codesandbox.io/s/material-demo-forked-xlcji. Your assistance in achieving this customization would be greatly a ...

What is the best way to access the rendered child components within a parent component?

I am seeking a way to retrieve only the visible child components within a parent component. Below is my unsuccessful pseudo-code attempt: parent.component.html <parent (click)="changeVisibility()"> <child *ngIf="visible1"></child> ...

Install the @agm-core package onto Angular 14

Encountering an error while attempting to install agm-core Encountering npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: undefined@undefined npm ERR! Found: @angular/[email protected] npm E ...

Checking for the existence of a value in an object using Angular loops

I am seeking assistance in verifying the presence of a specific value within an object. My Object = (vagas.etapas) "Etapas" : { "05daf060-87cb-47cf-8c98-65b36941613d" : "Name 1", "0bf7aabf-42df-4f7d-86dc-af81e6cef394 ...

The efficiency of React Context API's setters is remarkably sluggish

I have a goal to implement a functionality where the background gradient of a page changes depending on whether the child's sublinks are expanded or collapsed. To achieve this, I am using the useContext hook. However, I've noticed that although e ...

Ways to retrieve and upload a blob from a file object

After receiving a file object via an HTML input on-change event in my component.html: onFileSelected(event) { this.selectedFile = event.target.files[0]; } Now, I need to send a POST request to upload the image to the database. The database only acc ...

Issues with utilizing a generic type in an Arrow function in the Typescript Playground

When I try to use a generic type with an arrow function in Typescript Playground, I get an error message saying Cannot find name 'T' For more details, check out this link function hasAllProperties <T>(obj: any, props: (keyof T)[]): obj is ...

Tips for integrating custom code into your Angular cli service worker

Although I have successfully generated and configured the service worker using a config file generated by Angular CLI, I am struggling to find documentation on how to add custom code to the ngsw-worker.js file. I want to include functions such as push no ...

How do I assign a default value to an optional parameter in a derived class in Typescript?

One of my classes is called ClientBase: export class ClientBase { constructor(private uri: string, private httpClient: HttpClient) { } // Contains Various Methods } I have multiple subclasses that are derived from the ClientBase For instance: @I ...

I am unable to access the 'UserName' property in Angular 2 because it is undefined

I have tried multiple solutions, but none of them have helped me solve this issue... I am struggling to identify the problem in my code... HTML CODE :: <input type="text" class="form-control" placeholder="Please Enter Your Username" [(ngModel)]="curr ...

Tips on using the map and filter methods to narrow down a nested array based on specific object

I am struggling to filter JSON data based on a specific date using Array.Filter and Map. The code I have tried below is not yielding the desired results. Can someone please provide guidance on how to effectively filter JSON data based on a particular date ...

Using Angular 4 to transfer data from a dynamic modal to a component

Currently implementing material design, I have set up a dialogService for dynamically loading MdDialog. My goal is to create a search dialog with filters that, upon submission, directs the user to a search-results component route. However, I am struggling ...