0

When I am using jQuery in phtml file, I get error in console saying "Uncaught ReferenceError: require is not defined". And my jQuery code is

<script type="text/javascript">
    require(['jquery', 'jquery/ui'], function($){ 
            alert("Hello world");
    });
</script>

Thanks in advance ...!

Rob
  • 14,746
  • 28
  • 47
  • 65
Sachin Bhave
  • 31
  • 1
  • 4
  • 1
    Possible duplicate of [Javascript error : Uncaught ReferenceError: require is not defined](https://stackoverflow.com/questions/45723462/javascript-error-uncaught-referenceerror-require-is-not-defined) – ventiseis Dec 15 '17 at 08:00
  • I didn't understand @ventiseis – Sachin Bhave Dec 15 '17 at 08:11
  • `require` isn't a standard `js` function. [There seems to be another way to include libs in magento](https://magento.stackexchange.com/questions/97184/how-to-use-jquery-library-in-magento-2), but I'm surely no `magento` expert. _Furthermore, you don't need `jquery` for an `alert`_. What do you want to do anyway? – ventiseis Dec 15 '17 at 08:20

1 Answers1

0

There might be some Error While generating Js in your magento setup:

Please execute bin/magento setup:upgrade

(to remove static, generation, someother temporary files),

then bin/magento setup:static-content:deploy and see if this error still happens With Following Simple Jquery Alert.

require(["jquery"],function($){
     $(document).ready(function(){
          alert('Jquery Loaded');
     })
 })

Thankx

Rizwan Khan
  • 211
  • 3
  • 19