rkit / react-select2-wrapper

Wrapper for Select2
MIT License
163 stars 97 forks source link

TypeError: this.el.select2 is not a function #36

Closed afgarcia86 closed 8 years ago

afgarcia86 commented 8 years ago

I am pulling my hair out trying to figure out why select2 stopped working for me. My best guess is that a package I updated is conflicting with this one. However I figured I would ask here to see if there is an easy way to resolve the issue. Thanks for your help.

afgarcia86 commented 8 years ago

Actually I was able to resolve it after finding (https://github.com/rkit/react-select2-wrapper/issues/31). I remove the node_modules inside the react-select2-wrapper (jquery). Then I included that version of jquery in my package and I guess its not being included twice or in the incorrect order now.

nsisodiya commented 8 years ago

https://github.com/dopeddude/react-select2-wrapper/commit/98ca7c52b53687bbf93edc6f5bc891dec289dba2

ashwinik001 commented 8 years ago

The reason for the above issue was in the following dependency tree

├─┬ react-select2-wrapper@0.6.1
│ ├─┬ select2@4.0.3
│ │ ├── almond@0.3.2
│ │ └── jquery-mousewheel@3.1.13
│ └── shallow-equal-fuzzy@0.0.2

jquery-mousewheel@3.1.13 depends on the "jquery": ">=1.2.2" and thus it brings jquery 3.0 while the react-select2-wrapper@0.6.1 still depends on the "jquery": "^2.1.4", and hence the version mismatch. And hence the issue probably due to twice/incorrect loading of jquery.

So, with the above commit as mentioned by @nsisodiya , in my local I was able to resolve the issue.

As the package compiled output was required for the local testing so I went with the following steps:

In my root `package.json` updated the repo reference as
"react-select2-wrapper": "dopeddude/react-select2-wrapper"
And then run the following commands
$ cd node_modules/react-select2-wrapper/
$ npm i
$ npm run compile
$ mv node_modules/ node_modules_bak/
$ cd ../../

In future, When the react-select2-wrapper library itself upgrades to the latest jquery version, and thus they publish it to npm. Then the above steps will not be needed and repo reference can be reverted.

afgarcia86 commented 8 years ago

Sounds good to me I can close this if you would like.

rkit commented 8 years ago

I released a new version (1.0.0-beta1), please try (#38)

ashwinik001 commented 8 years ago

@afgarcia86 : yes, please close the issue. The respective PR "https://github.com/rkit/react-select2-wrapper/pull/38" is merged and now you can refer to the latest published version as 1.0.0-beta1 on your package.json.

rkit commented 8 years ago

Guys, tomorrow I'll release 1.0.0 (not beta)

afgarcia86 commented 8 years ago

I tested the beta, it worked for me :shipit:

aberonni commented 7 years ago

I'm having this same issue in tests while using the latest version. For some reason I get it only inside tests with jest. If I force select2 version to 4.0.3 I don't encounter the issue anymore.

Later I will try and see if I can reproduce consistently.

scottybollinger commented 6 years ago

I also am still receiving this issue with 1.0.4-beta. Also only in my jest tests

CWSites commented 5 years ago

I'm having the same issue with Jest unit tests when mounting a component with Select2, I tried bumping select2 to version 4.0.3 locally but that didn't fix anything for me.

I noticed that the fix that was merged above is altering the jquery dependency to be >=2.1.4 meaning it would accept 3.x.x. Prior to this change the dependency was ^2.1.4 which meant that it would accept any newer version that was not greater than or equal to 3.x.x. Were there any changes needed to the codebase for react-select2-wrapper to work with jQuery version 3.x?