Question

We keep receiving this log and stack trace from JQMigrate, but it seems to just be a warning. Is there a way to just straight up disable logging in production?

enter image description here

Was it helpful?

Solution

I ended up overriding the core jquery-migrate in our theme so I could set the migrateMute option.

In my theme require-jsconfig.js I set this override:

var config = {
  paths: {
    // disable jQuery migrate console output
    'jquery/jquery-migrate': 'js/jquery-migrate'
  }
}

Then copied the code jquery-migrate.js file to the theme js directory, and added this line towards the top:

// Set to true to prevent console output; migrateWarnings still maintained
jQuery.migrateMute = true;

OTHER TIPS

One should mute jquery.migrate before it gets initialised.

js/mute-migrate.js

requirejs(['jquery'], function ($) {
    $.migrateMute = true;
    $.migrateTrace = false;
});

requirejs-config.js

var config = {
    paths: {
        "mute-migrate":"js/mute-migrate"
    },
    shim: {
        'jquery/jquery-migrate': ['jquery','mute-migrate']
    }
}

In order not to overwrite any magento core files I just created a javascript file with this code

require(
    ['jquery'],
    function ($) {
        $.migrateMute = true;
        $.migrateTrace = false;
    }
);

I included the file in the head in default.xml

<link src="js/disable-jquery-migrate-warnings.js" />

A little bit hacky way but it works. You can create requirejs-config.js file in your theme and reassign jquery-migrate to an empty file

Example:

var config = {
    paths: {
        'jquery/jquery-migrate': 'js/empty'
    },
};

and create empty file js/empty.js

The solution posted by @thaddeusmt works great but I found an even better one. If you already have a js file you include everywhere, you can just add this to the top:

require(['jquery'], function($) {
    $.migrateMute = true;
});

so it looks something like this:

require(['jquery'], function($) {
    $.migrateMute = true;
});
// the rest of the js file...
require([
    "jquery",
    "jquery/ui",
    "mage/translate",
    "domReady!",
    "Magento_Ui/js/modal/modal"
], function ($) {
    // ...
});

You can actually do it without any additional scripts and just using RequireJS config:

var config = {
    shim: {
       'jquery/jquery-migrate': {
            init: function () {
                jQuery.migrateMute = true;
                jQuery.migrateTrace = false; // if needed
            }
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top