Cannot find type definition file for 'cordova' : diagnostic plugin

Hi,

I am unable to build my ionic 3 project after adding “Diagnostic” plugin.

There is a transpile error:

typescript: .....app/plugins/cordova.plugins.diagnostic/cordova.plugins.diagnostic.d.ts, line: 6
            Cannot find type definition file for 'cordova'.

       L5:  * "Dangerous" permissions that need to be requested at run-time (Android 6.0/API 23 and above)
       L6:  * See http://developer.android.com/guide/topics/security/permissions.html#perm-groups
       L7:  * @type {Object}

How can I resolve this problem? Following is the version information:

    "@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",
    "cordova": "^7.0.1",
    "cordova-android": "6.3.0",
    "cordova-browser": "^4.1.0",
    "cordova-ios": "^4.5.3",
    "ionic-angular": "^3.7.1",

did you install the npm module?
npm install --save @ionic-native/diagnostic

Also add Diagnostic to your providers list in your app.module.ts
import { Diagnostic } from '@ionic-native/diagnostic';

And then use it like described here:

You also need to have @ionic-native/core installed. You find the documentation for it here:

Thanks but this doesn’t make any difference!

Do you use isWifiAvailable? If so, you have to add the permission in your config.xml

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

There are also many other methods of diagnostic plugin where you need do add permissions to your config.xml first.

I am not using any methods. I intend to use “Location” and the respective permission already exists in my config.xml.

I have just added the plugin. No use in the app yet.

But it is not transpiling(compile time error when building the application). Tried changing the location of cordova typings but nothing worked!

Can you please send the output of ionic info, your app.module.ts, your package.json dependencies, how they are now, and some more information of the error, if there are some lines before and after what you posted about it.

Thanks but that’s a lot of info and i don’t think it would be worth wasting our time on figuring out the versions! I have dropped this plugin and using BackgroundGeolocation plugin as it provides the same methods for location and it is working fine.

Great. Nice to hear, that you found a solution for your problem.

You can fix it by installing cordova types:

npm install @types/cordova --save

2 Likes