Cordova is not defined and Facebook login error

I’ve followed this to a tee -

When running ionic serve --lab (or on device via simulator or an actual device build) I’m getting the following errors.

On start:

Uncaught ReferenceError: cordova is not defined

That’s coming from:
* @author Ally Ogilvie
* @copyright Wizcorp Inc. [ Incorporated Wizards ] 2014
* @file - facebookConnectPlugin.js
* @about - JavaScript interface for PhoneGap bridge to Facebook Connect SDK

if (cordova.platformId == "browser") {

When I click on the Facebook login button, nothing happens (both in browser and on device) and I’m getting the error:

TypeError: Cannot read property ‘getLoginStatus’ of undefined
at Scope.$scope.facebookSignIn (

Which is: facebookConnectPlugin.getLoginStatus

I had it all working 2 days ago and now I’m unsure what’s happened.
Any assistance or ideas would be very much appreciated.

Thank you!

on browser the native compoments are not availble --> you need to build your app to get this work.
Maybe the plugin is not added correctly.

run “ionic state reset” - to reinitialize your project (platforms and plugins)

To avoid such errors in browser --> check first if cordova is defined:

if (window.cordova)

Thanks @bengtler - I’ve now wrapped that initial if statement as follows.

if (window.cordova) {
  if (cordova.platformId == "browser") {
      var exec = require("cordova/exec"); //line 181

That error is now resolved but then it comes to line 181 where it errors as

require is not defined

As I mentioned, even when I build the app on device (even in Xcode emulator), the Facebook login button does not work. I can’t seem to find what the issue is.

I have run “ionic state reset” several times and still no luck.

ehhhm you are trying to load node-module in your app … this will not work at all.

Ah! I’ve only added the index.js (from the Facebook plugin) in to index.html based on someone else having success with it.

Removing still gives similar issues :confused:

I removed
<script src="lib/facebook-connect-plugin/index.js"></script>

Now the only error I get (on clicking Fb login) is:

facebookConnectPlugin is not defined
at Scope.$scope.facebookSignIn (

@bengtler All resolved now :slight_smile:

The cause was actually these two push packages;


Did an ionic state restore and now it’s back to working. Thanks for helping out :thumbsup: