How to bring in a module from another package in Angular 4

This is a fundamental query.

As an individual just starting with Angular and npm, this may seem like a basic question for some. However, despite extensive research, I haven't been able to find a solution.

Before embarking on a project, I want to create a small proof of concept. I aim to utilize a package named Imported within another package called Importer

The package.json file of Importer lists Imported as a dependency:

"dependencies": {
    ...
    "imported": "file:../Imported",
    ...
}

As expected, Imported can be found in the node_modules folder of Importer.

I have followed Angular's guidelines on reusing modules. The sample they provide is exactly what I am attempting, albeit from within a dependency.

Consequently, I imported ImportedAppModule in Importer's app.module.ts.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';


import { AppComponent } from './app.component';
import { ImportedAppModule } from 'imported/src/app/app.module';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule, 
    ImportedAppModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

In addition, I exported the component in Imported's app.module.ts :

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';


import { ImportedAppComponent } from './app.component';


@NgModule({
  declarations: [
    ImportedAppComponent
  ],
  imports: [
    BrowserModule
  ],
  exports: [
    ImportedAppComponent
  ],
  providers: [],
  bootstrap: [ImportedAppComponent]
})
export class ImportedAppModule { }

Despite this setup, I encountered the following error:

ERROR in ../imported/src/app/app.module.ts Module build failed: Error: \imported\src\app\app.module.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

It appeared that I needed to include this dependency in tsconfig.app.json. However, I also came across information suggesting otherwise and that it should be included in the Importer's bootstrap array. I tried both approaches, but neither proved successful. Nevertheless, the specific configuration details are not covered in this query.

So, here's my dilemma - What's the standard procedure for handling this situation? Am I moving in the right direction? If so, what should be my next step?

I attempted using ng build --aot in the Imported package and added the dependency to the dist folder in Importer initially. Unfortunately, it resulted in a failure stating the absence of a package.json file. Subsequently, I considered resorting to jit methodology; however, my preference remains leaning towards aot.

Your advice and guidance will be greatly appreciated. Thank you in advance!

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

Ensuring uniformity in picture size while uploading images in Angular by resizing and including white borders

Currently, I am working with pictograms and I am looking to showcase all the pictograms that the user has in both grid list and grid tiles formats. However, the challenge lies in the fact that the aspect ratio of the pictograms varies significantly depen ...

Attempting to personalize the CSS for a tab within a table in Material design is unsuccessful

Within my Angular 5 application, I have implemented the Material API. One of the components in my project is a table with 2 tabs structured like this: <mat-tab-group> <mat-tab> <mat-table> <!-- content --> </mat- ...

Angular does not wait for the backend service call response in tap

Does anyone have a solution for subscribing to responses when the tap operator is used in a service? edit(status) { dataObj.val = status; // call post service with status.. this.service .update(dataObj) .pipe(takeUntil(this._n ...

A guide on combining two native Record types in TypeScript

Is it possible to combine two predefined Record types in TypeScript? Consider the two Records below: var dictionary1 : Record<string, string []> ={ 'fruits' : ['apple','banana', 'cherry'], 'vegeta ...

What is the best way to display multiple HTML files using React?

Looking to develop a web application using React that consists of multiple HTML pages. For instance, login.html and index.html have been created and linked to URIs through the backend - resulting in localhost:8080/login and localhost:8080/index. However, R ...

ERROR: Unable to call function getTime in Typescript

While working on my function in Typescript, I encountered an issue with two sets of data in the database - date and time, both expecting strings. When users select a date, I trigger a POST request to set the time for them. To handle this scenario, I creat ...

Global installation of NPM packages with CLI may result in encountering the error message "command not found"

This has happened to me twice in the past. The first time, I thought it was an issue with NPM, so I removed Node & NPM and stopped using the problematic package. I did a fresh installation and started working on another project. I installed the package (in ...

Having trouble obtaining the ref.current.offsetWidth?

I have been working on creating a contextMenu. My goal is to retrieve the offsetWidth and offsetHeight from ref.current, but when I console.log it, it shows as undefined. const ContextMenu: React.FC<ContextMenuProps> = props => { const thisCom ...

Tips for preventing "script info" from appearing before the actual output when running npm script my-script

When I execute the command below: $ npm run test There is some information about the test script: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d3024703032392831381d6c736d73">[email protected]</a> test ...

Deploy a package to npm containing solely the contents of the dist folder's subdirectories

Here's the layout of my package: mypackage |--- src | |--- component1 | `--- component2 `--- dist |--- component1 `--- component2 For npm publishing, I want it to exclude the dist directory like this: mypackage ...

Manipulate dropdown choices by interacting with the dropdown form control in an Angular application

Is there a way to dynamically set options based on the form control name in Angular? For example, if we have a countries dropdown, we typically assign all countries to a specific variable and iterate over them using *ngFor. I am looking to change the opt ...

Altering Angular Material Dimensions and Customizing the Appearance of md-dialog-container

Currently, I am implementing Angular Material on my website and utilizing the md-dialog component for displaying popups in my gallery. While the default animation and styling are appealing, I would like to customize the dimensions of the hidden md-dialog-c ...

Challenge encountered with asynchronous angular queries

Dealing with asynchronous calls in Angular can be tricky. One common issue is getting an array as undefined due to the asynchronous nature of the calls. How can this be solved? private fetchData(id){ var array = []; this.httpClient.get('someUrl ...

Ways to properly assign a key in a Generic Interface as the interface key

Can someone assist me with TypeScript generics? I am wondering how to access the T["value"] field within the ActionAdd interface. type UserValue = { username: string; }; interface User { id: number; value: UserValue; } interface ActionAdd<T = unkn ...

How can I exclude the last parameter from a function type in Typescript?

If I have a function type like this: type FunctionType = (a: number, b: string, c: boolean) => void How can I create a new type with the last parameter removed? type NewFunctionType = OmitLastParameter<FunctionType> Desired type for NewFunctionT ...

"Windows Ember CLI: A Guide to Getting Started with Ember

Attempting to set up Ember cli on my Windows 7 system. Node and npm have been successfully installed, however upon running the command 'npm install -g ember-cli' I encounter an error message. Is there a step that I may have overlooked? ...

Caught off guard by this promise: TypeError - Attempting to access a property that does not exist in my Ionic 2 application

I'm encountering an issue with native Facebook login that displays the following error message: Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined I have shared my entire project code below. Although I am able to ...

What are some optimal techniques for implementing content-security-policy on an Angular website?

I am currently working on enhancing the security of an Angular website by implementing security headers in IIS. While most of the headers are functioning correctly without any issues, I have encountered a roadblock with the content-security-policy header. ...

Make sure to declare rest parameters first when using Typescript

I am dealing with a function that takes in multiple string arguments and one final argument of a complex type, which is called Expression. This particular code looks like this in JavaScript: function layerProp(...args) { const fields = args.slice(0, -1) ...

I'm encountering an issue with the generator-meanjs when trying to name a module "copywars" - it keeps throwing the error "Unknown provider: $stateProvider". What could be causing this problem?

I recently started using the MEAN stack, so I decided to create a game called CopyWars using yeoman generators. Follow these steps to reproduce: Download and launch mongodb then install npm sudo npm install -g generator-meanjs mkdir copywars-meanjs cd c ...