Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jScrollPane loads its own jQuery when used in webpack #386

Open
paul-bjorkstrand opened this issue Aug 18, 2021 · 1 comment
Open

jScrollPane loads its own jQuery when used in webpack #386

paul-bjorkstrand opened this issue Aug 18, 2021 · 1 comment

Comments

@paul-bjorkstrand
Copy link

Recently, I was moving some code from a legacy static files to webpack, and I noticed something curious:

When using webpack to import jScrollPane, I wasn't seeing it in $.fn as an instance function. After some digging, I saw that the jquery version that it was being attached to was 3.6.0, when the version in the project was different. Of the three jquery plugins we had, 2 were working, this one was not. The difference was intriguing. Below is my findings and some additional details on potential fixes.


In jquery-match-height, it was working as expected. The only difference that I can tell is that there is no dependency on jQuery in package.json. My guess is that plugin had the same problem, and just solved it by removing the dependency.

In jquery-mousewheel, it is doing something different. If you see in jquery.mousewheel.js, for CommonJS modules, it is not calling the factory, it is just exposing it in the exports, which means you call the factory in your code, like below (which works perfectly):

import $ from  'jquery';
import jqueryMousewheel from 'jquery-mousewheel';

jqueryMousewheel($);

To do it canonically (at least NPM canonical), it might be better to make jquery a peerDependency. This would have the benefit that your existing users don't have to change anything other than ensure that they have jquery added as a dependency in their projects (which they almost certainly do already).

To take it to the next level, you could do the same for your other dependency, jquery-mousewheel (funny, since I mentioned it above).

Either way you decide to fix it (peer dependency or do it like jquery-mousewheel) would make it a whole lot easier to use in webpack for migrating projects.

@illuusio
Copy link
Collaborator

Do you have time to make PR to make it peerDependency as currently it's going to be long lag to get fixes like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants