3

I just NuGet update my jquery from 1.8.3 to 3.1.1. Then I keep getting this error on every page. After looking around, it seem like jquery is getting execute multiple times, but that doesn't seem to be the case when I check in developer tool.

So, this is where it happens.

jQuery.Deferred.exceptionHook = function( error, stack ) {

    // Support: IE 8 - 9 only
    // Console exists when dev tools are open, which can happen at any time
    if ( window.console && window.console.warn && error && rerrorNames.test( error.name ) ) {
        window.console.warn( "jQuery.Deferred exception: " + error.message, error.stack, stack );
    }
};

jQuery.readyException = function( error ) {
    window.setTimeout( function() {
        throw error;
    } );
};

On line "window.console.warn...." it has warning - jQuery.Deferred exception: a(...).parents(...).andSelf is not a function

And the error is thrown on line "thrown error" - Uncaught TypeError: a(...).parents(...).andSelf is not a function

Any idea why this happens?

Tek
  • 64
  • 1
  • 2
  • 12

1 Answers1

15

jQuery deprecated andSelf in version 1.8 and removed it in version 3.0.0, which is why it's "not a function" in 3.1.1.

You should be using $.fn.addBack instead, but the code you've posted is the part of jQuery that handles errors, this is not the problem, somewhere in your code there's a piece of code that says a(...).parents(...).andSelf() which should be changed to a(...).parents(...).addBack().

adeneo
  • 312,895
  • 29
  • 395
  • 388
  • I never use andSelf but maybe the developer before me did. I'll try search for it. Thanks. – Tek Nov 23 '16 at 18:16
  • @Tek - Somewhere, it's being used, and as this is a breaking change, you have to fix the code manually and replace instances of `andSelf` with `addBack` to get it working in 3.1.1 – adeneo Nov 23 '16 at 18:19
  • Awesome thanks! Jquery-ui, jquery-validate, and DataTable libraries use andSelf. I replaced them all with addBack and the error went away. That shouldn't break anything right? I rely on jquery-validate a lot. I honestly have no idea what the two functions does. – Tek Nov 23 '16 at 18:28
  • 1
    No, it shouldn't break anything, but I'm also guessing most of those plugins are already updated, or will be shortly, to work with the new major release of jQuery, so you could check their websites if there are new versions out. – adeneo Nov 23 '16 at 18:38
  • Great. Kinda weird that jquery-ui still use andSelf though, I mean I updated both at the same time. Anyway, thanks again! – Tek Nov 23 '16 at 18:41