The error "Failed to log in. Cannot read property getPackageManager of undefined in Angular 2

Recently, I came across the nativescript-appList Plugin, but unfortunately encountered a runtime error stating "Cannot read property getPackageManager of undefined."

My code implementation within the constructor of an Angular2-NativeScript project is as follows:

import * as AppList from "nativescript-applist";

 // inside the constructor

 console.log("First", "Test");

    AppList.getInstalledApps(function(apps) {

        console.log("Second", "Test");

        }, {
            withIcons: true
        });

Strangely, when running the application in the command prompt, only the log for "console.log("First", "Test");" appears, while the expected log for "console.log("Second", "Test");" doesn't show up.

Answer №1

The compatibility of the plugin with an Angular project seems to be an issue, but there is a simple solution to make it function properly. To achieve this, you will have to manually edit the source code of the plugin. You can either clone the repository and implement the necessary changes followed by running npm pack to generate an updated tgz file, or directly modify the code within

node_modules/nativescript-applist/Apps.android.js
after installing the plugin (although this method is not recommended as changes may be lost when removing node_modules folder).

To enable the plugin in Angular, follow these steps: - Access

node_modules/nativescript-applist/Apps.android.js
- Place the first two lazily loaded properties inside the method

For example:

var androidApp = app.android;
var androidAppCtx = androidApp.context;

function getInstalledListOfApps(callback, cfg) {
    // additional code here

Adjust to:

function getInstalledListOfApps(callback, cfg) {
    var androidApp = app.android;
    var androidAppCtx = androidApp.context;

    // additional code here

Once done, your plugin should now work smoothly!

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

Struggling with setting up eslint in my typescript project

Below is the contents of my package.json file: { "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.13.0", "@typescript-eslint/parser": "^5.13.0", "airbnb": "^0.0.2&qu ...

When you eliminate the Angular root element, what are the consequences that follow?

I am in the process of manually bootstrapping an Angular application. ngDoBootstrap(app) { app.bootstrap(AppComponent); } Each time the root element is removed from the DOM and re-injected, I bootstrap the application again. This cycle repeats multip ...

Prevent swiping beyond the final slide in a react-slick carousel

I am currently using react-slick to create a carousel, and I have a specific requirement to prevent swiping and dragging of slides once the last image is reached. After conducting some research, I attempted to set swipe: false on the final slide, which suc ...

How do I set class properties in TypeScript using an array of values for initialization?

My constructor has the following structure: constructor(values: Object = {}) { //Constructor initialization Object.assign(this, values); } However, it currently requires named initialization like this : new Inventory({ Name: "Test", ...

Increasing the font size of the mdToolTip in Angular2 Materials

Recently, I've been trying to adjust the font size in mdToolTip. While looking through the pre-themes CSS, I came across this class: .mat-tooltip { background: red; font-size: 50px; } However, it seems to be ignoring the font-size syntax. Can any ...

Using the expect statement within a Protractor if-else block

My script involves an if-else condition to compare expected and actual values. If they do not match, it should go to the else block and print "StepFailed". However, it always executes the if block and the output is "step passed" even when expected does not ...

Fix the static-class-block error when running Jest tests in TypeScript

Recently, I included the antlr4ng (version 3.0.4) package in my TypeScript project's package.json, which is based on Node.js version 20.11.1. It functions well except when used within a Jest test, where it throws this error at runtime: SyntaxError: /U ...

I keep seeing "Uncaught TypeError: Unable to retrieve property 'get' from undefined" error message popping up

Currently, I am attempting to retrieve a JSON from a separate microservice (local) utilizing a different port. There is uncertainty as to whether the issue lies within my configuration or the microservice itself. Despite successfully displaying the JSON on ...

A guide on initializing an Angular 2 component and setting public properties

My service is returning the expected data when injected into a component. However, I am encountering an issue where the response remains undefined when I subscribe to the service method and assign it to a public variable during initialization of the compon ...

Issue encountered with CSS-in-JS in a TypeScript, Webpack, React project: No matching overload found

My project involves Webpack, Typescript, and React Hooks with CSS-in-js for styling a div. I encountered an error while hovering over the style prop in the Menu component. I'm unsure about where to bind the CSSProperties. (JSX attribute) React.HTMLAtt ...

Customize Angular Material styles uniquely across various components

Within my application, I am utilizing two components that contain tab groups. The first component serves as the main page, where I have adjusted the CSS to enlarge the labels by using ViewEncapsulation.None. The second component is a dialog, and I aim to m ...

Having trouble retrieving documents from a nested collection in Firebase

I am attempting to retrieve all documents from Firebase that are based on a query. Here is my current firebase structure: https://i.stack.imgur.com/tXrX8.png Even though I have two documents inside the "ListaFavorite" collection, when I check using empty ...

Establishing the context for the input template by utilizing ng-template, ng-container, and ngTemplateOutlet

I am facing a challenge with a customizable component that utilizes an ng-container to display either a default template or a template passed in as an input. The issue arises when I try to set the context of the passed-in template to the nesting component ...

Execute ngrx/effect outside of Angular's zone to avoid timing out in Protractor testing

Recently, I began implementing end-to-end tests for my application and encountered timeout issues with Protractor and ngrx/effects. One of the effects in question dispatches an action every few minutes: @Effect() setSessionTimer$ = this.actions$ ...

Guide to iterating through an Observable<Object[]> to generate an array of objects

Google Firestore collection named users is structured as follows : { "contactNumber":"0123456789", "email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="88e2e7e0e6ece7edc8efe5e9e1e4a6ebe ...

How can you dynamically register a Pipe in Angular 2 based on a certain condition?

Conditionally declaring Services using Angular2's dependency injection mechanism is a powerful feature. An example from thoughtram's website demonstrates this: { provide: Engine, useFactory: () => { if (IS_V8) { return new V8Engi ...

Regular expressions are effective tools, but they may not be as functional within an

Trying to validate URLs using a regex has been tricky. The regex I have works perfectly fine on regex101.com, but for some reason it keeps failing validation when implemented in my Angular field. I'm at a loss as to how to tweak it so that Angular wil ...

NgModel may not consistently reflect changes in text input

I'm currently working on a situation where I need the ngModel to be updated based on specific conditions. Here is the template: <mat-form-field> <mat-label>val:</mat-label> <input matInput [(ngModel)]="someVal" ...

Error encountered when serving Angular due to node_modules/@types incompatibility (Build Issue)

When attempting to run 'ng build' after npm install, I encounter the following error message: ERROR in node_modules/@types/node/globals.d.ts(713,19): error TS2304: Cannot find name 'bigint'. node_modules/@types/node/ts3.6/base.d.ts(13,2 ...

Declaring variables or fields with specific type restrictions

Imagine we have a generic interface: export interface IKeyValue<K, V> { key: K; value: V; } Now, our goal is to define a variable or field and restrict the types that can be used as K and V: public items: IKeyValue<K extends Type1, V ex ...