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?

1
  • please let me know if you have any issue Nov 9, 2016 at 12:03

1 Answer 1

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>
7
  • Remove var and check in frontend Nov 9, 2016 at 11:48
  • thanks @Rakesh still it throws $ is not a function Nov 9, 2016 at 12:03
  • you can just deploy run command, remove var folder and clear browser cache Nov 9, 2016 at 12:10
  • yes I have done clear redis cache, remove var/*, static content deploy, clear browser cache. Nov 9, 2016 at 12:11
  • i have update answer, you have missing jquery in script in template, require(['jquery','gworks/jquery'] Nov 9, 2016 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.