skratchdot / react-bootstrap-multiselect

A multiselect component for react (with bootstrap). This is a react port of bootstrap-multiselect.
http://projects.skratchdot.com/react-bootstrap-multiselect/
Other
119 stars 62 forks source link

problem on the first example #57

Open ofirk12 opened 7 years ago

ofirk12 commented 7 years ago

i get this meesage : /react-bootstrap-multiselect/lib/bootstrap-dropdown.js:2 [2] if (typeof jQuery.fn.dropdown !== "undefined") return jQuery; when i write var Multiselect = require('react-bootstrap-multiselect'); what can be the problem?

HellMagic commented 7 years ago

i discover the problem also

skratchdot commented 7 years ago

Are you including jQuery in your app, or is it being injected by 'react-bootstrap-multiselect'? I've changed the code recently due to people wanting to inject their own version of jQuery, so there might be a bug with that part.

Do you have a repo I can check out (or an online example)?

aaronkw commented 7 years ago

I'm also running into that error. I'm not including jQuery explicitly in my app.

skratchdot commented 7 years ago

@aaronkw - what's the actual error message you see in the console? I don't really understand the original bug report without links to code. What bundler are you using (browserify/webpack/rollup)?

redkyo017 commented 7 years ago

I've got the same issue , the bundler is webpack

aaronkw commented 7 years ago

The issue for me is that previously (pre 2.2.0) the require('./boostrap-dropdown.js') was inside the if block that checks that there's a working window. With the new version, it breaks server-side rendering because bootstrap-dropdown.js gets loaded whether or not there's a window, and thus jQuery.fn is undefined.

2.1.0:

if (typeof window !== 'undefined' && typeof document !== 'undefined') {
  //Necessary for Universal Javascript apps
  //since JQuery requires a working window
  var $ = require('./bootstrap-multiselect.js').init(
    require('./bootstrap-dropdown.js').init(
      require('jquery')
    )
  );
}

2.2.0

var bsMultiselect = require('./bootstrap-multiselect.js');
var bsDropdown = require('./bootstrap-dropdown.js');
// setup jQuery
var $;
if (typeof window !== 'undefined' && window && window.jQuery) {
  $ = window.jQuery;
} else {
  $ = require('jquery');
}
sman591 commented 7 years ago

Related: #73 and #77