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

The initial update of the view does not occur when a component property changes in Angular 2 RC6

I am currently facing an issue with a component in my project. This component calls a service to retrieve locally stored JSON data, which is then mapped to an array of objects and displayed in the component view. The problem I am encountering is that the v ...

Issue updating Bootstrap in ASP.Net Core 2.1 with Angular Template

Every time I start a new ASP.Net Core 2.1 project with the angular template and try to update the bootstrap version from 3 to 4 in package.json, it ends up breaking my application. Despite numerous attempts such as deleting the node_modules folder and rein ...

The error occurred while using NPM watch: ReferenceError: The variable "_" is not recognized in the file "../node_modules/angular-google-maps/dist/angular-google-maps.js" at line 1, column 1 (

I'm currently working with Angular and encountered an error in the console section of my browser after restarting my computer: Unhandled Promise rejection: _ is not defined ; Zone: <root> ; Task: Promise.then ; Value: ReferenceError: _ is not de ...

Angular displays RouterLink as regular text

I am currently learning Angular and encountering an issue with the routerLink attribute in my <a> tag. When I add the routerLink, it changes to text and becomes unclickable. Can anyone help me identify what is causing this problem? Here is a snippet ...

What is the best way to incorporate an exported TypeScript class into my JavaScript file?

One of my JavaScript files is responsible for uploading a file to Microsoft Dynamics CRM. This particular JavaScript file makes use of RequireJS to reference another JavaScript file. The referenced JavaScript file, in turn, was compiled from multiple Typ ...

tsconfig is overlooking the specified "paths" in my Vue project configuration

Despite seeing this issue multiple times, I am facing a problem with my "paths" object not working as expected. Originally, it was set up like this: "paths": { "@/*": ["src/*"] }, I made updates to it and now it looks like ...

Cross-origin request error persists despite configuring headers on the server. Unable to successfully relocate image to designated directory on the server

I am encountering a CORS error specifically when sending delete requests from Angular to Laravel. Additionally, I am facing issues with moving car model images to the directory during posting, resulting in errors. I have implemented a CORS middleware and a ...

Encountered an issue with npm install where it cannot read the property 'startsWith' of null

I have been trying to find a solution to this problem everywhere, but without success. Most answers suggest that there might be an issue with the proxy settings. Every time I attempt to use npm install -g package-name, an error occurs. npm ERR! Cannot rea ...

Issue with retrieving relative time using Moment.js - fromNow()

I want to utilize moment.js to display relative time fromNow(), but I am encountering an issue where the values are being rounded and showing higher durations instead of exact completion times. For example, moment().subtract('s',110).fromNow() / ...

What is the process for listening to custom events in Angular 4 components that have been loaded using routing?

In the app.component.html file <li routerLinkActive="active current"> <a [routerLink]="['/stats']"> Cluster stats </a> </li> When we route to the DisplayAllStatsComponent, how can we ...

Troubleshooting offline pagination with dynamic MatTable containing matInputs (Angular 5 Material Design)

I have an issue with my component that contains an empty form with matInputs, as well as a mat-table with matInputs in the rows, all enclosed in mat-cards. The number of rows in the table is dynamic and based on another input called 'range'. So, ...

What is the proper way to tap into the features provided by DefinitelyTyped in typescript?

While working on my Angular2 app that deals with money amounts, I decided to use dinero.js to handle money values. However, I am encountering difficulties in accessing certain features in Typescript. Following the instructions, I installed the DefinitelyT ...

The 'books' property cannot be found on the 'client' type

I am currently integrating the Google Book API into my project and encountering an issue while trying to add a book to a library using gapi.client. The error I keep receiving is as follows: This is the request : gapi.client.books.mylibrary.bookshelves.volu ...

Having trouble compiling Angular CLI version 8.3.21 with the command ng serve

Upon trying to compile my first Angular app, I encountered an error when running ng serve: ERROR in ./src/styles.css (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded! ...

Personalized design for Material Tooltip in Angular 17

I am currently working on an angular 17 application that utilizes the latest Material components. My project heavily incorporates the Tooltip component, but I am facing challenges when it comes to customizing it to my preferences. While I did succeed in c ...

Utilizing the Loess npm module in conjunction with Angular 4

I am attempting to incorporate the Loess package into my project. The package can be found on NPM and offers various regression models for data fitting. I successfully installed it using npm install loess --save, and it now resides in the node_modules dire ...

Conceal the choice when aria-expand is in a deactivated state

I'm currently facing a challenge with hiding an option in mat-select only when aria-expanded is false. In the dropdown menu, I have both "Select All" and "Deselect All" options. However, when the menu is closed, it displays "Deselect All" by default ...

How to anticipate an error being thrown by an observable in RxJS

Within my TypeScript application, there exists a method that produces an rxjs Observable. Under certain conditions, this method may use the throwError function: import { throwError } from 'rxjs'; // ... getSomeData(inputValue): Observable<s ...

Switching templates within a component based on conditions in Angular 2

Situation: I am working with a component called COMP that needs to load one of two templates, which are named TEMPLATE_1 and TEMPLATE_2. The choice between the two is based on the type of user who is logged in - either an ADMIN user or a NORMAL user. Can ...

What issues arise from using ng-content within a web component?

I have a unique component structure for my website: <div (click)="popup.showAsComponent()"> <ng-content></ng-content> </div> Here is how I implement it: <my-web-component><button>Click!</button></my ...