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:
1 |
php bin/magento setup:static-content:deploy -f |
Now check if you still face the error with the below JQuery alert:
1 2 3 4 5 6 7 8 |
<?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.
That’s it. Any doubts in the error or its solution? If so, feel free to mention them in the Comments section below. I’d be happy to help.
Do share the solution with Magento community via social media.
Thanks.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
Easily Learn to Set up Order Confirmation Email in Magento 2
What is Magento – Here’s what you need to know
Next