In Ionic 2, Getting Cannot find name 'cordova'. even after install the typings

I am getting Cannot find name ‘cordova’. even after installing the typing command as ionic sugested to install by@types but still same error .
I tried this npm install @types/cordova --save

I am trying to use pushwoosh plugin but getting error Cannot find name ‘cordova’.
var pushwoosh = cordova.require(“pushwoosh-cordova-plugin.PushNotification”);

Plugin: cordova plugin add pushwoosh-cordova-plugin

Is anyone resolved this…please help

@chakraveer Try this:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

declare var cordova: any;

...

@Component({

...

this.storageDirectory = cordova.file.documentsDirectory;

...

Thanks for the reply…

if am adding declare var cordova: any; on top then its failing at run time.

Error: Uncaught (in promise): ReferenceError: cordova is not defined
Ionic Framework: 3.0.1
Ionic App Scripts: 1.3.0
Angular Core: 4.0.0
Angular Compiler CLI: 4.0.0
Node: 6.9.5
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36

If you’re trying to run this in a browser, it’s not going to happen unless you install the “browser” cordova platform (assuming this plugin has support for that platform). Ordinary “ionic serve” is not going to work.

Yes but if there is any error in src folder then gulp will not update the www folder to deploy new changes.

Is there anything related to Typing or @type as I can see the index.d.ts file under global folder but app.component.ts not getting the reference of cordova.

It’s not working at all working tried lots of ways. It’s just third party plugin Pushwoosh I am trying to use.

Sorry, but I am having trouble understanding you. The ionic build process doesn’t use gulp. If you are getting errors, you need to fix them. Unless you deal with the special browser platform, cordova is never going to be defined if you are running in a browser.

Thanks… Its working in Device .
No typing installation required for Pushwoosh plugin only declare var cordova: any; requred to add.

It was my mistake I was thinking that if the browser showing the plugin error then www folder will not update from src folder and deployed app was crashing due to another line of error.

2 Likes