1

app/code/Vendor/Module/view/frontend/requirejs-config.js

var config = {
    map: {
        '*': {
            'gworks/jquery':'Vendor_Module/js/jquery.min'           
        },

    }
};

In template file, I called like

<script type="text/javascript">
require(['gworks/jquery'],function($) {
    $(window).load(function () {
         alert('load from external jquery');
    });
});
</script>

In browser net tab above added js loaded [200 ok]

http://domainame/pub/static/frontend/Vendor/theme/en_US/Vendor_Module/js/jquery.min.js

but it still throw error in browser console like TypeError: $ is not a function and alert also does not come.

I am not familiar in requirejs so I doubted myself anything am I missing here?

  • please let me know if you have any issue – Rakesh Jesadiya Nov 9 '16 at 12:03
1

Keep below syntax in requirejs-config.js file

   var config = {
        paths: {            
                'gworks/jquery':"Vendor_Module/js/jquery.min" ,
            },   
        shim: {
            'gworks/jquery': {
                deps: ['jquery']
            },
        }
    };

In script,

<script type="text/javascript">
require(['jquery','gworks/jquery'],function($) {
    $(window).load(function () {
         alert('load from external jquery');
    });
});
</script>
  • Remove var and check in frontend – Rakesh Jesadiya Nov 9 '16 at 11:48
  • thanks @Rakesh still it throws $ is not a function – Bilal Usean Nov 9 '16 at 12:03
  • you can just deploy run command, remove var folder and clear browser cache – Rakesh Jesadiya Nov 9 '16 at 12:10
  • yes I have done clear redis cache, remove var/*, static content deploy, clear browser cache. – Bilal Usean Nov 9 '16 at 12:11
  • i have update answer, you have missing jquery in script in template, require(['jquery','gworks/jquery'] – Rakesh Jesadiya Nov 9 '16 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.