When trying to use the exported Ionic 3 class in TypeScript, the error "Cannot find name 'ClassName'" occurs

When working on my Ionic 3 Application, I encountered an error stating "Cannot find name" when trying to use certain plugins. I initially imported the plugin like this:

import { AndroidPermissions } from '@ionic-native/android-permissions';

and then declared it in the constructor like this:

(public androidPermissions: AndroidPermissions)
, which resulted in the error
([ts] Cannot find name 'AndroidPermissions'.)
.

Trying to declare the plugin in app.module.ts and as a Provider led to the following error:

[ts]
Type 'AndroidPermissionsOriginal' is not assignable to type 'Provider'.
Type 'AndroidPermissionsOriginal' is missing the properties 'provide' and 'useFactory' [2322]

After further research, I found that importing the plugin with ngx solved the initial error:

import { AndroidPermissions } from '@ionic-native/android-permissions/ngx'

However, upon invoking it, a new error was thrown:

Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
    at AndroidPermissions.requestPermissions (http://192.168.0.13:8100/build/vendor.js:69796:154)
    ... //(more stack trace)

A similar issue arose when using the Network plugin and SMS plugin.

I also attempted to change the target to es6 and jib to include es2016 in tsconfig.json but none of these solutions worked for me. Below is a snippet of my tsconfig.json file:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "src/**/*.spec.ts",
    "src/**/__tests__/*.ts"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

Answer №1

If you happen to be utilizing ionic version 3 (not the most up-to-date one) Please take a look at the provided documentation below https://ionicframework.com/docs/v3/native/android-permissions/

start by eliminating
ionic cordova plugin remove cordova-plugin-android-permissions

then, re-add it with the following steps:

$ ionic cordova plugin add cordova-plugin-android-permissions

$ npm install --save @ionic-native/android-permissions@4

Answer №2

give these commands a try: - delete package-lock.json


ionic cordova platform remove android
npm install
ionic cordova platform add <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfbeb1bbadb0b6bb9fe9f1ecf1ef">[email protected]</a>
ionic cordova plugin add cordova-plugin-android-permissions
npm install --save @ionic-native/android-permissions@4

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

What steps are necessary to integrate barrel file imports with my Angular 2 application?

Following the Angular 2 style guideline 04-10 Create and Import Barrels can be challenging, as it may lead to unexpected file loading issues. When running my app, I noticed that Angular attempts to load a non-existent file named "my-component-name-here.js" ...

Converting an array into an object by using a shared property in each element of the array as the key

I have an item that looks like this: const obj = [ { link: "/home", title: "Home1" }, { link: "/about", title: "About2" }, { link: "/contact", title: "Contact1" } ] as const and I want to p ...

Encountering a problem during the installation of angular-route.d.ts

When trying to install angular-route using the command typings install angular-route --save -global, I encountered an error. Can someone help me resolve this issue? typings ERR! message Unable to find "angular-route" ("npm") in the registry. typings ERR! ...

Caution: Updating a component is not possible during the rendering of another component. ReactJS

I am encountering an error in my ReactHooks/Typescript application with a Navigation component that renders a PatientInfo component. The PatientInfo component is conditionally rendered based on the props it receives, determined by a searchbox in another ch ...

The new experimental appDir feature in Next.js 13 is failing to display <meta> or <title> tags in the <head> section when rendering on the server

I'm currently experimenting with the new experimental appDir feature in Next.js 13, and I've encountered a small issue. This project is utilizing: Next.js 13 React 18 MUI 5 (styled components using @mui/system @emotion/react @emotion/styled) T ...

Importing CSS properties from MUI v5 - A comprehensive guide

I'm working with several components that receive styles as props, such as: import { CSSProperties } from '@material-ui/styles/withStyles' // using mui v4 import because unsure how to import from v5 paths import { styled } from '@mui/mat ...

Setting up Angular integration with ASP.NET Core on Azure App Service

Currently, I am working on a web application that combines Angular and .NET 5, and my goal is to host it on two separate Azure App Service instances - one for testing and the other for production environments. To achieve this setup, I have referred to the ...

Angular 12's BehaviorSubject should have been empty object array, but it unexpectedly returns undefined

Exploring different scenarios with a livesearch functionality: No user input (observable = undefined) No results found (observable = empty array) Results found (observable = non-empty array) The issue lies in how my behavior subject interprets an empty a ...

Step-by-step guide on uploading an image file using Nextjs

I am attempting to achieve the following: Upload an image file to a Next.js application Process it using cjwbw/real-esrgan:d0ee3d708c9b911f122a4ad90046c5d26a0293b99476d697f6bb7f2e251ce2d4 Retrieve the enhanced version of the image Is there anyone who can ...

Issues with NgRx testing - NullInjectorError: Service provider not found

When attempting to write unit tests for effects, I encountered the error NullInjectorError: No provider for StationsListService!. The code in my stations.effects.ts file looks like this: @Injectable() export class StationsListEffects { constructor(priva ...

Using TypeScript: Retrieve enum type value in type definition

I'm encountering an issue while attempting to define a specific type based on the value of an enum. enum E { A = "apple", B = "banana", C = "cherries" } // Defining the type EnumKey as 'A' | 'B ...

Incorporating aws-sdk into Angular 2 for enhanced functionality

I'm currently working on integrating my Angular2 application with an s3 bucket on my AWS account for reading and writing data. In the past, we used the aws-sdk in AngularJS (and most other projects), so I assumed that the same would apply to Angular2 ...

Having Trouble Setting Default Value in React Typescript MUI Autocomplete

I am encountering an issue with my React and Typescript code using MUI with the use of hook form. The problem arises when trying to set a default value for an Autocomplete field, resulting in the following error message: I am seeking assistance in resolvi ...

When utilizing mat-select within a Custom Element (web component), the options are displayed outside of the shadow DOM

When I incorporate a mat-select element into my custom element, the options appear outside of the shadow dom in the HTML. This means that the options are not displayed directly below the select control. After some investigation, I discovered that setting ...

Struggling to locate the module 'firebase-admin/app' - Tips for resolving this issue?

While working with Typescript and firebase-admin for firebase cloud functions, I encountered the error message "Cannot find module 'firebase-admin/app'" when compiling the code with TS. Tried solutions: Reinstalling Dependency Deleting node_modu ...

How can the NavBar be refreshed once a user logs in?

I recently followed a helpful guide on implementing a login system in my React TS application. However, I encountered an issue with the NavBar component within my app compared to how it was coded in the App.tsx file of the guide. Specifically, I found it c ...

Establish a default value for cascading Angular dropdowns

In my JSON data, each country has an ID associated with it. I am trying to set the default value of a select option to 'selected' based on a specific ID (in this case, 100). Here is the code for my select element: <select (change)="onNational ...

What could be the cause of error TS2339 popping up: "Property 'scan' is not recognized on type 'Subject<any>'?

UPDATE: It's come to my attention that there may have been a shift from chaining to piping in RxJS 6.x. Can anyone confirm? See more at: This is my introduction to working with RxJS streams. I'm attempting to create some basic ones, but encounte ...

How to integrate a chips feature in Angular 4 using Typescript

Struggling to incorporate a chips component into my Angular web application, which comprises Typescript, HTML, and CSS files. After grappling with this for weeks without success, I have yet to find the right solution. To review my current code, you can a ...

Obtain the coordinates of the pixel in an image on the canvas when a mouse

I am currently working on a project that involves using canvas. I have set a picture as the background of the canvas and would like to be able to get the original pixel point when clicking in the image area. In order to achieve this, I need to convert canv ...