Can classes from an external package be imported into an Angular library within an Angular app using Openlayers?

I am currently developing an Angular library that configures an OpenLayers map as an Angular component. The component is functioning properly, but I need to access classes and constants from a package imported by the library, specifically OpenLayers.

To work around this issue, I have also installed the same package within the Angular app. However, there seems to be some compatibility issues between the two packages, even though they are using the same version. It's difficult to articulate the problem in plain text, so I will provide some pseudo code to illustrate further.

In my Angular library, I have the following method:

import { Feature} from "ol";
....

public addFeature(feature: Feature) {
    this.layer.getSource().addFeature(feature);
}

And in my Angular app, I have the following snippet:

import { Feature} from "ol";

public test() {
    const feature = new Feature();
    myLibService.addFeature(feature)
}

However, when I run this, I encounter the following error:

Argument of type 'Feature' is not assignable to parameter of type 'Feature'. Types of property 'on' are incompatible.

This issue can be resolved by changing the type of Feature in the library function "addFeature" to type any, which is something I would prefer to avoid. Creating a new Feature() inside my library works without any problems.

My Desired Outcome Ideally, I would like to import "Feature" from the "ol" package installed within my-lib directly into my Angular app. Is there a way to achieve this?

Etc:

import { Feature} from 'my-lib/node_modules/ol';

If you need further clarification or additional information, please feel free to ask. The provided code is purely pseudo-code, but conveys the same details as the actual implementation.

Thank you in advance!

I have attempted to install the "ol" (OpenLayers) package in both my Angular app and Angular library, with both using the same version.

Answer №1

Today, I successfully tackled this issue by incorporating openLayers as a peerDependency in my Angular library and then installing it normally in the consuming app.

"peerDependencies": {
"@types/proj4": "^2.5.2",
"@types/ol": "^6.5.3",
"ol": "^7.2.3-dev.1676300784989",
"proj4": "^2.8.0" }

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

Exploring resources within a library in Angular

I need help accessing assets from a shared library within my nx workspace. Here is the structure: /apps -- my-app // ... /libs -- shared -- assets -- resources -- translation.json The shared lib has an alias defined as @my-company/s ...

Determine if a condition is met in Firebase Observable using scan() and return the

Within Firebase, I have objects for articles structured like this: articles UNIQUE_KEY title: 'Some title' validUntil: '2017-09-29T21:00:00.000Z' UNIQUE_KEY title: 'Other title' validUntil: '2017-10-29T21:00:00 ...

Navigating to the detail page following a POST request in RTK query: A step-by-step guide

In my React RTK-query form, I am facing an issue where after a POST request is made, the form should navigate to the next step. However, in order to do that, I need to obtain the id of the newly created record. The backend auto-increments the id and does n ...

The outdated expo-cli legacy version is not compatible with Node +17

After installing expo-cli and setting the environment variable, I encountered the following error: The outdated expo-cli does not work with Node +17. It is recommended to switch to the updated Expo CLI (npx expo). Uncaught Error: EPERM - operation not all ...

Typescript: Securing Data with the Crypto Module

I am currently working on encrypting a password using the built-in crypto module. Previously, I used createCipher which is now deprecated. I am wondering if there is still an effective way to achieve this. Here is the old code snippet: hashPassword(pass: ...

Trouble accessing images from database in Angular 2 with Firebase

Recently, I've integrated an image upload feature for my database using the following function: private saveFileData(upload: Upload): void { this.firebaseAuth.authState.subscribe(auth => { this.db.list(`uploads/${auth && auth.email && au ...

Changes in the width of the left column in Bootstrap 4 are based on the content present in the right column

I seem to be struggling with implementing Bootstrap effectively. My goal is to achieve a layout similar to this, once the "Load Report" button is clicked and there is data to display: https://i.stack.imgur.com/c3nuO.png In the image, there are two column ...

Resolving the non-null assertion error in TypeScript and React: A step-by-step guide

My code snippet is as follows: type ItemProps = { status?: string; } <Items status={status!} /> // encountering an error with a warning about forbidden non-null assertion // @typescript-eslint/no-non- ...

React has an unmet peer dependency

I encountered issues while attempting to install npm package node-saas ├── UNMET PEER DEPENDENCY [email protected] └── UNMET PEER DEPENDENCY [email protected] npm ERR! peer dependency missing: react@^0.14.1, as required by [email ...

Can you explain the concept of TestBed in Jasmine?

Recently, I have started using Jasmine with Angular 2 and have encountered an issue while working with the TestBed object in my test cases. The error message reads as follows: Please call "TestBed.compileComponents" before your test. Can anyone advise on ...

Making sure the checkbox stays selected in an angular environment

After experimenting with Angular 9 and a custom input, I achieved the following result => https://stackblitz.com/edit/angular-ivy-rgsatp My goal was to prevent users from disabling a radio button that is currently checked. Therefore, I made changes in ra ...

Adjust the button sizes in Ngprime

I am trying to customize my primeng buttons because they appear too large for my project. I found in the documentation that I can make them smaller by using: <p-button label="Small" icon="pi pi-check" styleClass="p-button-sm&quo ...

What could be causing the HTTP response Array length in Angular to be undefined?

Currently, I am facing an issue while retrieving lobby data from a Spring Boot API to display it in my Angular frontend. After fetching the data and mapping it into an object array, I encountered a problem where the length of the array turned out to be und ...

Can I create a unique Generic for every Mapped Type in Typescript?

I've got a function that accepts multiple reducers and applies them all to a data structure. For instance, it can normalize the data of two individuals person1 and person2 using this function: normalizeData([person1, person2], { byId: { init ...

Tips for addressing style issues within innerText

I am trying to use PrismJS to highlight HTML code, but the inner text function doesn't recognize line breaks (\n). <pre class="language-markup background-code"><code [innerText]="getHtmlCode()""></code> I have been working wi ...

Combining Angular 4 with a pre-existing Spring Boot web app utilizing JSP components

Currently, I have a live Spring Boot web application that uses jsp and JavaScript. My goal is to gradually update existing pages with Angular when time allows. While I am new to Angular, most of the information I have come across suggests that it require ...

What exactly do Dependencies mean in Angular?

As a beginner in Angular, the concept of dependencies has come up several times during my learning process. Despite my efforts to search for a clear definition of Dependencies in Angular on Google, I have been unsuccessful. Could someone please provide a ...

ESLint not functioning properly on TypeScript (.ts and .tsx) files within Visual Studio Code

After installing the ESLint extension in VSC, I encountered an issue where it was no longer working on the fly for my React project when I introduced Typescript. In the root of my project, I have a .eslintrc file with the following configuration: { "pa ...

Using Angular 6 pipes can simplify observable operations by eliminating the need for explicit typing

Recently, I upgraded my application from Angular5 to 6. Upon completing the update, I proceeded to migrate to rxjs6, which resulted in a change in my code where I was utilizing the takeWhile method. As a result, in order to subscribe to a service, my code ...

Using Javascript to parse SOAP responses

Currently, I am working on a Meteor application that requires data consumption from both REST and SOAP APIs. The SOAP service is accessed using the soap package, which functions properly. However, I am facing challenges with the format of the returned data ...