Not sharing single instance of jQuery/simple assignment failing?

24 Views Asked by At

I don't know how to explain this one. I'm trying to debug import 'datatables.net' isn't setting $.fn.dataTable. My theory was that I have 2 copies of jquery.

To debug I added

$.poop = 345
$.fn.somethingUnique = 123

before

import factory from 'datatables.net'

Then I added a break statement inside jquery.dataTables.mjs which appears to be the file that webpack is loading.

enter image description here

If you look at the "Watch" on the right there (in Chrome devtools) you will see $.poop is undefined but jQuery.poop is set as expected.

If you look on the left there, there's a line let $ = jQuery;

So if they're equivalent... how can they not be equivalent? What's going on here?

1

There are 1 best solutions below

0
On

I think that was exactly it, datatables.net was importing jQuery 3. DevTools was tricking me by showing the uncompiled code.

Adding

    "resolutions": {
        "jquery": "^2"
    },

to package.json fixed it for me (using yarn 3.x)