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

Possible different jquery objects modified by plugins #244

Open
weaverryan opened this issue Jan 22, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@weaverryan
Copy link
Member

commented Jan 22, 2018

Hi guys!

I just wanted to drop this here for some discussion:

https://knpuniversity.com/screencast/javascript-webpack/provide-plugin#comment-3712073331

tl;dr;

If a jQuery plugin properly uses require (like bootstrap-datepicker), then it appears possible that it will modify a different jquery object than you get in userland when using require('jquery'). The solution is to add a jquery alias (Eonasdan/bootstrap-datetimepicker#1319 (comment)).

This makes sense: each package gets its own set of dependencies, so it would make sense. We should consider adding the jquery alias, possibly when the user enables autoProvidejQuery. It's tricky, because I want to balance wtf moments and not make more wtf by adding this alias (there are probably some edge case use-cases where the alias could mess something up).

@tdarlic

This comment has been minimized.

Copy link

commented Jan 28, 2018

Thanks for pointing it out. I couldn't figure this out on my own.
I ended up doing it this way using node path

module.exports = Encore.getWebpackConfig();

let config = Encore.getWebpackConfig();
config.resolve.alias = {
    'jquery': path.join(__dirname, 'node_modules/jquery/src/jquery')
};
module.exports = config;
@stof

This comment has been minimized.

Copy link
Member

commented Apr 3, 2018

that's because a jquery plugin should actually have a peer-dependency to jquery, not a dependency (as it wants to alter the dependency used by the requester instead)

@weaverryan

This comment has been minimized.

Copy link
Member Author

commented Apr 12, 2018

Yea, so really, if we decide to fix this, it’s because we’re working around a bug in some js library that has done this incorrectly.

@stof

This comment has been minimized.

Copy link
Member

commented Apr 12, 2018

anyway, if you have multiple jQuery copies locally, because some plugins are not declaring their dependencies the right way, you cannot always fix this with an alias (what if they are incompatible versions ?).

So this should get reported to the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.