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?

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.