webpack-encore icon indicating copy to clipboard operation
webpack-encore copied to clipboard

Possible different jquery objects modified by plugins

Open weaverryan opened this issue 7 years ago • 5 comments

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 (https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1319#issuecomment-208339466).

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).

weaverryan avatar Jan 22 '18 15:01 weaverryan

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;

tdarlic avatar Jan 28 '18 10:01 tdarlic

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)

stof avatar Apr 03 '18 15:04 stof

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.

weaverryan avatar Apr 12 '18 01:04 weaverryan

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.

stof avatar Apr 12 '18 10:04 stof

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Feb 04 '25 12:02 carsonbot

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Aug 05 '25 12:08 carsonbot

Hello? This issue is about to be closed if nobody replies.

carsonbot avatar Aug 19 '25 12:08 carsonbot

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

carsonbot avatar Sep 02 '25 12:09 carsonbot