Search code examples
ionic2ngcordova

Cannot find name 'cordova'. ionic build ios


I am using ionic2 build . I did ionic plugin add cordova-plugin-file and used following code.

import {File} from 'ionic-native';
@Injectable()
export class GlobalVars {
  constructor(platform:Platform) {
    platform.ready().then(() => {
       this.appRootFolder = cordova.file.documentsDirectory;
    }
  }
}

then I did ionic build android and I got this error

Cannot find name 'cordova'

After 2 hour of struggling , I resolved the issues by following commands

npm install -g typings
typings install dt~cordova --save --global 
typings install dt~cordova/plugins/filesystem --save  --global

This helped in building android , but still fails for iOS. when I run this ionic build ios I still get

Cannot find name 'cordova'


Solution

  • I wrote this line(declare var cordova:any;) at the top of file

    import {File} from 'ionic-native';
    declare var cordova:any;
    

    And the problem is solved for me.