RC0 : Cannot find name 'cordova'

Now that I’ve upgrade my app to RC0, I can no longer build for android platform when using cordova plugin.

I get the error ngc: Error: ‘Cannot find name ‘cordova’’ when I use the following code:

         let targetPath = cordova.file.externalDataDirectory;

the same code works with ionic2 beta version

any idea ?

I’ve fixed it by adding
declare var cordova: any;

before my class declaration. It’s in ionic documentation, but strangely I didn’t have to do that before RC0.

I had this solution before RC0 which worked. But now, building with RC1, I got the following error:

[11:33:29]  SyntaxError: Unexpected token (6:8) in .tmp/app/main.prod.ts 

And the line 6 is:

declare var cordova: any;

Is Typescript 2.0.3 still compatible with declare var ?

Hard times. I hope we find the answer soon

Considering the previous post was 12 months ago, one hopes we have found the answer.

Are you having issues?

Yes. I am using ionic serve -l. But I read somewhere that cordova will never be defined in ionic serve…

That is correct. Cordova is for mobile, so will not be available in the browser.

If you can use Ionic Native you should use that, as it will handle the errors for you.

Otherwise, you’ll need to use platform to make sure Cordova is available, e.g. platform.is('cordova').

Okay I see. Then my issue becomes one about using a node package that doesn’t play nice with ionic.

Someone made a cordova plug-in to circumvent this but it seems that I need to figure out how to make the node package work.

Thank you