Hello,
I am currently working on an Ionic 2 project and I cannot get any Cordova plugin to function at all.
I am on a Windows computer, and all relevant software is up to date as of today.
I don’t believe I’m missing anything; I’ve searched thoroughly for a solution, and tried to work around the problem in a dozen different ways, and come up empty-handed. Multiple fairly recent sources I’ve found online suggest this is the solution.
I’ll go through the simplest steps that reproduce the problem.
First, create a project:
ionic start MyApp blank --v2 --ts
Then, add a desired plugin, and a platform:
cd MyApp
ionic plugin add cordova-plugin-inappbrowser
ionic platform add android
At this point the plugin should be globally accessible, right? The API says it can be called through cordova.InAppBrowser.open()
. So let’s just check if the cordova
object exists. I edited app.ts
like this (the console.log()
line is the only thing I added):
import {App, Platform} from 'ionic-framework/ionic';
import {HomePage} from './pages/home/home';
import {Type} from 'angular2/core';
@App({
template: '<ion-nav [root]="rootPage"></ion-nav>',
config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
export class MyApp {
rootPage: Type = HomePage;
constructor(platform: Platform) {
platform.ready().then(() => {
console.log("Cordova = " + cordova);
});
}
}
So I try building it, and:
ERROR in [default] C:/git/MyApp/app/app.ts:17:32
Cannot find name 'cordova'.
(Two irrelevant and easily fixed errors in the file animation.d.ts
also appear.)
Well, I can’t use the plugin if I can’t access the object. (This particular plugin is supposed to overwrite window.open()
, as well—it doesn’t.) The error isn’t just build-time, either; it’s still missing at runtime.
I have tried the following:
- Other plugins. Not one of them would load.
- Creating the project as JS instead of TS. No change.
- Using
.d.ts
files, in several different ways (usingtypings
, usingtsd
, manually downloading them from DefinitelyTyped, writing my own, etc.) - Trying to access plugins in
home.ts
instead of the mainapp.ts
. - Fixing the errors in
animation.d.ts
. - Several other things as well.
Am I missing something obvious or is this just a bug in the starter code?
Thank you very much for your time and help.