Skip to content

Possible different jquery objects modified by plugins #244

Open
@weaverryan

Description

@weaverryan
Member

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/tempus-dominus#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).

Activity

tdarlic

tdarlic commented on Jan 28, 2018

@tdarlic

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

stof commented on Apr 3, 2018

@stof
Member

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

weaverryan commented on Apr 12, 2018

@weaverryan
MemberAuthor

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

stof commented on Apr 12, 2018

@stof
Member

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.

carsonbot

carsonbot commented on Feb 4, 2025

@carsonbot
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @weaverryan@stof@tdarlic@carsonbot

        Issue actions

          Possible different jquery objects modified by plugins · Issue #244 · symfony/webpack-encore