Diagnostic Plugin Install Not Working

Hello! I’m trying to use the diagnostic.isLocationAuthorized() function.

I ran:

ionic cordova plugin add cordova.plugins.diagnostic
npm install --save @ionic-native/diagnostic

and I got the error(s):

Native: tried calling Diagnostic.isLocationAuthorized, but the Diagnostic plugin is not installed.
Install the Diagnostic plugin: 'ionic cordova plugin add cordova.plugins.diagnostic'
ERROR – Error: Uncaught (in promise): plugin_not_installed — polyfills.js:2

app.module.ts:

import { Diagnostic } from '@ionic-native/diagnostic';

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    AboutPage,
    SelectProductPage,
    LoginPage
  ],
  imports: [
    BrowserModule,
    HttpModule,
    HttpClientModule,
    AngularFireDatabaseModule,
    AngularFireAuthModule,
    AngularFireModule.initializeApp(firebaseConfig),
    IonicModule.forRoot(MyApp),
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    AboutPage,
    SelectProductPage,
    LoginPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    Geolocation,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    FirebaseProvider,
    GooglePlus,
    AuthProvider,
    AppVersion,
    CommonProvider,
    Diagnostic
  ]
})
export class AppModule {}

component where I’m using the plugin:

import {Component, NgZone } from '@angular/core';
import {LoadingController, MenuController, NavController, Platform, ViewController} from 'ionic-angular';
import { SelectProductPage } from "../select-product/select-product";
import {CommonProvider} from "../../providers/common/common";
import { Diagnostic } from "@ionic-native/diagnostic";


@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage{
  stores: any;
  locationServicesNotAuthorized: boolean = false;
  searchStores: boolean;
  storeSearchText: string;

  constructor(private MenuCtrl: MenuController, private ViewCtrl: ViewController, private LoadingCtrl: LoadingController, private NavCtrl: NavController,
               private Platform: Platform, private Zone: NgZone, private Diagnostic: Diagnostic)
  {
    this.searchStores = false;
    this.storeSearchText = '';

    this.Diagnostic.isLocationAuthorized().then(locationIsAuthorized => {
      if(locationIsAuthorized) {
        this.getLocationAndFindStores();
      }
      else {
        this.locationServicesNotAuthorized = true;
      }
    });
  }

  ionViewWillEnter() {
    this.Platform.ready().then(() => {
      if(!this.stores) {
        this.getLocationAndFindStores();
      }
    });
    this.MenuCtrl.enable(true);
    this.ViewCtrl.showBackButton(false);
  }

  getLocationAndFindStores() {
    this.Diagnostic.requestLocationAuthorization().then(userAuthorizedLocationAccess => {
      if(userAuthorizedLocationAccess) {
        //Do some stuff
      }
      else {
          //Can't do that stuff.
      }
  }

package.json:

"scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "4.4.3",
    "@angular/compiler": "4.4.3",
    "@angular/compiler-cli": "4.4.3",
    "@angular/core": "4.4.3",
    "@angular/forms": "4.4.3",
    "@angular/http": "4.4.3",
    "@angular/platform-browser": "4.4.3",
    "@angular/platform-browser-dynamic": "4.4.3",
    "@ionic-native/app-version": "^4.3.1",
    "@ionic-native/core": "4.3.0",
    "@ionic-native/diagnostic": "^4.3.1",
    "@ionic-native/geolocation": "^4.3.0",
    "@ionic-native/google-plus": "^4.3.1",
    "@ionic-native/splash-screen": "4.3.0",
    "@ionic-native/status-bar": "4.3.0",
    "@ionic/app-scripts": "^3.0.0",
    "@ionic/storage": "2.0.1",
    "angularfire2": "^5.0.0-rc.1",
    "cordova-android": "^6.2.3",
    "cordova-ios": "^4.5.1",
    "cordova-plugin-app-version": "^0.1.9",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-device": "^1.1.6",
    "cordova-plugin-geolocation": "^2.4.3",
    "cordova-plugin-googleplus": "^5.1.1",
    "cordova-plugin-splashscreen": "^4.0.3",
    "cordova-plugin-statusbar": "^2.2.3",
    "cordova-plugin-whitelist": "^1.3.2",
    "cordova.plugins.diagnostic": "^3.7.1",
    "cordova.plugins.diagnostic.api-22": "^100.0.0-api-22",
    "firebase": "^4.5.1",
    "firebase-tools": "^3.13.0",
    "geofire": "^4.1.2",
    "ionic-angular": "3.7.1",
    "ionic-plugin-deeplinks": "^1.0.15",
    "ionic-plugin-keyboard": "^2.2.1",
    "ionicons": "3.0.0",
    "ios": "0.0.1",
    "promise-polyfill": "^6.0.2",
    "rxjs": "5.4.3",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.0.0",
    "typescript": "2.3.4"
  },
  "description": "XXXXX",
  "cordova": {
    "plugins": {
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-whitelist": {},
      "ionic-plugin-keyboard": {},
      "cordova-plugin-googleplus": {
        "REVERSED_CLIENT_ID": "XXXXXX"
      },
      "cordova-plugin-geolocation": {
        "GEOLOCATION_USAGE_DESCRIPTION": " "
      },
      "cordova-plugin-app-version": {},
      "cordova.plugins.diagnostic": {}
    },
    "platforms": [
      "android",
      "ios"
    ]
  }`Preformatted text`

Please edit your post, it is not very readable at the moment.
Use the </> button above the input field to format your code, command line output or error message (select the text first, then click the button or wrap it in ``` manually). Check the preview if it looks better. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.

You forgot the code you are actually running and what else you did to integrate the plugin into your code.

Thanks Sujan12. I’ve added the code.

Sujan, I’ve resolved this issue. My apologies for the request, but I believe Diagnostic was being implemented incorrectly on my end.

1 Like

Glad you could fix it!

Can you post what you had to change to make it work?

I believe it was as simple as updating my version of the Ionic CLI.

After running

npm i ionic@latest

it worked!

1 Like

Did you fix this error?
What was your mistake?