Cannot find name 'cordova'. ionic 5 build android

Viewed 1032

I use cordova exec to call a function of my local plugin,

command ionic cordova prepare android get me an error

error TS2304: Cannot find name 'cordova'.

enter image description here

Is folowing my function

    getUserData() {
    return new Promise((Resolve, Reject) => {
      this.platform.ready().then(() => {
        cordova.exec((ResponseData) => {
          this.UserData = ResponseData;
          console.log('Key chain data', ResponseData);
          Resolve(this.UserData);
        }, (err) => {
          this.UserData = null;
          console.log('Key chain data err', err);
          this.route.navigate(['/helps'], { queryParams: { Data: JSON.stringify(err) }});
          Reject(err);
        }, 'ConnectionSecurePlugin', 'getUserPass', [] );
      });

    });
  }

Can somebody help me please

Thanks in advance! :)

2 Answers

You have to declare cordova in that service file or ts file like

declare var cordova:any;

You have to declare that just after import statements. Because Cordova is not directly available like normal phonegap or Cordova projects

The solution I have found that works is:

// @ts-ignore
cordova.exec
..

Related