Why your JQuery plugins may be failing in 1.3.1

Of the ten plugins that run fine in a 1.2.1 in production app, three will never run in 1.3.1 without being hacked.
First one bootstrap3-typeahead.js v3.1.0
This one causes a Meteor build failure with a suggestion to install jquery
Here is the first few lines (for those that want the details):

if (typeof module !== 'undefined' && module.exports) {
    module.exports = factory(require('jquery'));
  }
  // AMD module is defined
  else if (typeof define === 'function' && define.amd) {
    define(['jquery'], function ($) {
      return factory ($);
    });
  } else {
    factory(root.jQuery);
  }
}

Installing jquery through npm will not help. You will have to modify this plugin (easy to do).

The second one is worse as it just doesn’t establish the global functions you need.
No errors, doesn’t work.
Its a light weight bootstrap validation library named Dominar.
Here’s its ‘factory’ function:

(function(factory) {
    if (typeof exports !== 'undefined')
    {
	module.exports = factory;
    }
    else
    {
	window.Dominar = factory(jQuery, Validator);
    }
}

Third is Datepicker for Bootstrap v1.5.0
same problem as above, slightly different code.

(function(factory){
    if (typeof define === "function" && define.amd) {
        define(["jquery"], factory);
    } else if (typeof exports === 'object') {
        factory(require('jquery'));
    } else {
        factory(jQuery);
    }

I assume there are boatloads of plugins that worked great pre 1.3 and no longer play well with Meteor.

5 Likes

Hey @stocksp,

Thanks for your explanation. Is there any recommended implementation for jQuery plugin authors that is compatible to Meteor 1.3?

Unfortunately, I’ve not seen or heard anything about a proper fix. The parsing/import code used by Meteor in 1.3 is the issue. Only @benjamn who wrote all the stuff would know what is wrong (and how to fix) the above code. I just removed all the ‘if’ clauses and forced the code to always ‘just use jQuery in the browser’. There may be ‘issues’ with this hack but its the best I could come up with. I assume (hope) as more and more folks run into this maybe it will get some attention.