{"id":936,"date":"2020-04-10T08:21:59","date_gmt":"2020-04-10T08:21:59","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/04\/10\/solved-uncaught-reference-error-require-js-is-not-defined-in-magento-2\/"},"modified":"2025-05-22T13:35:29","modified_gmt":"2025-05-22T08:05:29","slug":"solved-uncaught-reference-error-require-js-is-not-defined-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/solved-uncaught-reference-error-require-js-is-not-defined-in-magento-2\/","title":{"rendered":"Solved: Uncaught ReferenceError RequireJS Is Not Defined In Magento 2 [Step-by-step Method]"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Ever faced an error like \u201c<em><strong>Uncaught ReferenceError RequireJS Is Not Defined<\/strong><\/em>\u201d&nbsp;<em><strong>in Magento 2<\/strong><\/em>&nbsp;while using jQuery in pHtml file?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It may happen that while coping with a client\u2019s task, you face this error and it becomes a headache! But not any more with the below solution to solve this error!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solution for Uncaught ReferenceError RequireJS Is Not Defined In Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">While generating JS in Magento setup, there might be an error:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Execute&nbsp;<code>bin\/magento setup:upgrade<\/code>&nbsp;command to remove the static, generation, etc. files<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After, execute:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php bin\/magento setup:static-content:deploy -f<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now check if you still face the error with the below JQuery alert:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nrequire(['jquery'],function ($)\n{\n    $(document).ready(function()\n    {\n        alert('ok');\n    });\n});<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Whenever you use JQuery code in your development, prefer to use it in the above manner.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do share the solution with Magento community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever faced an error like \u201cUncaught ReferenceError RequireJS Is Not Defined\u201d&nbsp;in Magento 2&nbsp;while using jQuery in pHtml file? It may happen that while coping with&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-936","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=936"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/936\/revisions"}],"predecessor-version":[{"id":14975,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/936\/revisions\/14975"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}