Nimrod Yonatan Ben-Nes
Nimrod Yonatan Ben-Nes

Reputation: 386

Running Ionic at cca throw "Cannot read property 'Keyboard' of undefined" @ app.js:14

The following is what I did to setup Ionic in Chrome App for Mobile:

  1. Created a Chrome App for Mobile project - cca create projectname
  2. Created an Ionic project ionic start projectname_ionic
  3. Deleted all of the files from the Chrome App www folder except the manifest files and background.js - find projectname/www/* -not -name 'manifest*' | grep -v 'background.js' | xargs rm -rf
  4. Copied the content of the Ionic project www folder to the Chrome App www folder - cp -r projectname_ionic/www/* projectname/www/
  5. Commented out <script src="cordova.js"></script> at projectname/www/index.html since cca automatically inject it already

When trying to run the project I get the following error from app.js line 14 -

Uncaught TypeError: Cannot read property 'Keyboard' of undefined

When typing at the console of Chrome dev tools (remote debugging) window.cordova I do get an existing object, so the problem is that window.cordova.plugins is undefined.

btw the app itself does load up at the mobile and I can switch tabs, but at the Friends tab when I click on a name I do see that it got clicked but nothing happen beside that.

I also tried the following:

  1. projectname_ionic/plugins had 3 plugins which projectname/plugins missed so I added them using cca plugin add ... to projectname/
  2. Run ionic platform add android at projectname_ionic/ before copying the files
  3. Tried few older versions of Ionic (desperate I know :))
  4. And some other tries which I forgot already...

Anyone got an idea what should I do?

Thanks in advance!

Upvotes: 6

Views: 7368

Answers (3)

Irena Shai
Irena Shai

Reputation: 105

I started getting the same error after removing plugins directory (I had a hook that was adding the plugins as part of the add platform). There are 3 plugins that ionic adds for a new project. I did not have keyboard and console ones as part of my hook.

Check that you have following cordova plugins:

cordova plugin add ionic-plugin-keyboard
cordova plugin add org.apache.cordova.console
cordova plugin add org.apache.cordova.device

Once I added missing plugins to the ones added by hook the error was gone.

Also, if node_modules was removed, npm install will be needed.

Upvotes: 9

anataliocs
anataliocs

Reputation: 10747

When I tried to add the plugin on Mac OSX the plugin had a different name. You have to run this command in the project directory.

cordova plugin add ionic-plugin-keyboard

You can see the lib here: keyboard plugin

Upvotes: 4

JoshuaDavid
JoshuaDavid

Reputation: 9539

It sounds like you're not running this as an actual build -- are you using CADT? Even if you're testing with CADT on a device you will still NOT get window.cordova.plugins. Once you build the project with cca build and then install the apk on a device then the window.cordova.plugins will be defined.

Hatzlacha

Upvotes: 0

Related Questions