Solved: Uncaught ReferenceError RequireJS Is Not Defined In Magento 2 [Step-by-step Method]

Ever faced an error like “Uncaught ReferenceError RequireJS Is Not Defined” in Magento 2 while using jQuery in pHtml file?

It may happen that while coping with a client’s task, you face this error and it becomes a headache! But not any more with the below solution to solve this error!

Solution for Uncaught ReferenceError RequireJS Is Not Defined In Magento 2:

While generating JS in Magento setup, there might be an error:

Execute bin/magento setup:upgrade command to remove the static, generation, etc. files

After, execute:

php bin/magento setup:static-content:deploy -f

Now check if you still face the error with the below JQuery alert:

<?php
require(['jquery'],function ($)
{
    $(document).ready(function()
    {
        alert('ok');
    });
});

Whenever you use JQuery code in your development, prefer to use it in the above manner.

Do share the solution with Magento community via social media.

Thanks.

Table of Contents