9

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

7 Answers 7

4

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;
3
  • Going to mark this as the selected answer, as it's a bit cleaner than the first method that was given.
    – codestr
    Commented Feb 5, 2018 at 22:17
  • This helped, but didn't hide everything for me; I also had to include jQuery.migrateTrace = false; Commented Apr 18, 2019 at 9:15
  • 1
    magento.stackexchange.com/a/292260/36253 -> this is actually much cleaner solution Commented Feb 7, 2020 at 11:25
22

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']
    }
}
3
  • 12
    This is the cleanest solution and should be an accepted answer Commented Feb 7, 2020 at 11:24
  • 1
    This worked instantly for me!
    – Myron
    Commented Sep 1, 2021 at 8:15
  • For more control over the load order, add this: 'mute-migrate': { deps: ['jquery'] }, to the shim. Commented Jan 31 at 17:26
9

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" />
2

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

1
  • This works and I'll mark as accepted since its the only solution thats been offered, but I'd rather avoid having to make the request for the file at all if it's not going to be used.
    – codestr
    Commented Nov 28, 2017 at 15:19
2

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
            }
        }
    }
}
1

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 ($) {
    // ...
});
0

Quick question : In the case that you have already a bought theme, which will be the best or ideal location to do the override? I have a path like app/code/MGS/ClaueTheme/view/frontend/require-config.js !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.