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?
7 Answers
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;
-
Going to mark this as the selected answer, as it's a bit cleaner than the first method that was given.– codestrCommented 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 -
1magento.stackexchange.com/a/292260/36253 -> this is actually much cleaner solution Commented Feb 7, 2020 at 11:25
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']
}
}
-
12This is the cleanest solution and should be an accepted answer Commented Feb 7, 2020 at 11:24
-
1
-
For more control over the load order, add this: 'mute-migrate': { deps: ['jquery'] }, to the shim. Commented Jan 31 at 17:26
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
-
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.– codestrCommented Nov 28, 2017 at 15:19
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
}
}
}
}
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 ($) {
// ...
});
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 !!