Using jquery select2 within Electron Framework


#1

I have been using jQuery, bootstrap, select2 within Electron Framework Project. Recently, I updated NodeJs and npm, then started experiencing problem with loading select2 package. I am getting this error: "Uncaught TypeError: (...).select2 is not a function." whenever select2 function is called. I have searched, read and tried several solutions. So far I have tried, checking the order of (jQuery, Bootstrap and select2) being loaded that specific order, different versions of jQuery are not being attached to the html page, downloading all packages and using in the file through local path, manually trying to add select2 to .fn object. But nothing works for me. I also tried removing node_modules, clearing npm cache and installing everything. But that also didn’t help.

To isolate the problem, I downloaded the [electron-quick-start project](https://github.com/electron/electron-quick-start and replaced the index.html file with this gist file link to the index.html.

When I opened index.html file in the chrome browser, I see no error and select2 is loaded and I also see it in the Object $.fn. But when I started the electron project, it is giving me the same error as I was getting previously with my project. I am using Node v8.9.1, npm 5.5.1 (installed through homebrew).

I would appreciate any insights, link to any other posts which I might have missed and any suggestions to resolve this issue.


#2

I tried different versions (4.0.3, 4.0.4,4.0.5, 4.0.6-rc.0) of select2 within Electron. Only select2 version 4.0.3 worked within Electron.
Regarding the error in my project due to select2: npm installed a latest version of select2 (as specified with ‘^’ suffixed with version number) got installed causing that error. Now, I have made changes to the package.json of my project to install only version 4.0.3 of select2 and my project is running without any errors.