How to fix the jQuery Migrate warning in Magento 2?

To remove the warning JQMIGRATE: jQuery.attrFn is deprecated from the console, you must first create a storefront theme and apply it to your store. Within your theme directory, you create/modify the app/design/frontend/<module_folder>/<theme_folder>/requirejs-config.js file. Replace <module_folder>/<theme_folder> with your own.

var config = {
    shim: {
        'jquery/jquery-migrate': {
            init: function () {
                jQuery.migrateMute = true;
                jQuery.migrateTrace = false;
            }
        }
    }
}

Clear cache and redeploy.

The warning JQMIGRATE: jQuery.attrFn is deprecated is gone. We are still getting a log message:

In Magento 2.4.4, we can no longer use shim to set the variables. To accomplish the same thing, we need to create a custom JS file (for example app/design/frontend/<module>/<theme>/web/js/mute-migrate.js) with the following code:

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

Then we can set the requirejs-config.js to locate the JS file:

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

To remove JQMIGRATE all together, you need to create and apply a custom patch like the following file: https://devdocs.magento.com/guides/v2.4/comp-mgr/patching.html#custom-patches

patches/theme/remove-jquery-migrate.patch

diff --git a/view/base/requirejs-config.js b/view/base/requirejs-config.js
--- a/view/base/requirejs-config.js
+++ b/view/base/requirejs-config.js
@@ -14,7 +14,6 @@ var config = {
         }
     },
     shim: {
-        'jquery/jquery-migrate': ['jquery'],
         'jquery/jstree/jquery.hotkeys': ['jquery'],
         'jquery/hover-intent': ['jquery'],
         'mage/adminhtml/backup': ['prototype'],
@@ -40,9 +39,6 @@ var config = {
         'tinycolor': 'jquery/spectrum/tinycolor',
         'jquery-ui-modules': 'jquery/ui-modules'
     },
-    deps: [
-        'jquery/jquery-migrate'
-    ],
     config: {
         mixins: {
             'jquery/jstree/jquery.jstree': {

You can use the cweagans/composer-patches plugin to apply it to your Composer-based Magento 2 installation. https://devdocs.magento.com/guides/v2.4/comp-mgr/patching/composer.html

To apply the patch, edit the composer.json file, specifying the patch location:

"extra": {
        "magento-force": "override",
        "composer-exit-on-patch-failure": true,
        "patches": {
            "magento/module-theme": {
                "Remove JQMigrate": "patches/theme/remove-jquery-migrate.patch"
            }
        }
    }

Apply the patch. Use the -v option only if you want to see debugging information.

composer -v install

Update the composer.lock file. The lock file tracks which patches have been applied to each Composer package in an object.

composer update --lock

Clear cache and redeploy.

Here are a few more console warnings you may want to fix in Magento:

https://www.cyberic.net/how-to-fix-the-interpreting-unsafe-inline-as-a-hostname-warning-in-magento-2-4

https://www.cyberic.net/how-to-remove-the-frame-ancestors-error-message-in-magento-2-4

https://www.cyberic.net/how-to-fix-the-content-security-policy-warning-in-magento-2-4

2 thoughts on “How to fix the jQuery Migrate warning in Magento 2?

  1. Hi Eric,

    I have applied the fix above in app/design/frontend///requirejs-config.js on Magento 2.4.4, but it did not work.

    Can you try it on the latest Magento version?

    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *