Cannot add plugin to Ionic 2 Project


#1

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 (using typings, using tsd, manually downloading them from DefinitelyTyped, writing my own, etc.)
  • Trying to access plugins in home.ts instead of the main app.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.


Cordova plugins' <clobbers> tags don't work in Ionic
#2

Sorry for the bump, but can someone please help me out?

I know there are other topics about this, but none of them contain working solutions. I have tried everything. I feel like this is a new issue that was recently introduced into the starter code.


#3

Hi. The solution is in this thread. I got the inAppBrowser plug-in working yesterday.


#4

Hello Richard! I appreciate your taking the time to help me. However, the solution in that thread does not work for me. I have gone into more detail about why it does not work in that thread.


#5

Never mind, the issue was resolved. See the linked topic for the details.