I'm trying to load a plugin using requirejs but occasionally get an error, "$.fn is undefined" but if I reload the page the error disappears almost like now jquery is cached the problem is removed. I'm loading my libraries like this:
require(["jquery-1.4", "/script/jquery.autoSuggest.packed.js"], function($) {
$(function() {
//code
});
});
Can you see if there is anything wrong with this implementation that would cause this error? Require js is being added to the page as so:
<script type="text/javascript" src="http://website.co.uk/frameworks/requirejs/0.2.4/sharedmodules/require.js">
</script>
<script type="text/javascript"> requireMap = {
"jquery-1.4":"http://website.co.uk/sharedmodules/jquery-1.4"
};
require({ baseUrl: 'http://website.co.uk/', paths: requireMap });
</script>
This can't be changed as it's part of the framework I'm using.
Any suggestions?
Thanks!
order plugin is removed. use shim loading as follows
requirejs.config({
paths: {
'jquery': 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min',
'bootstrap': '../bootstrap/js/bootstrap.min',
'select2': 'vendor/select2',
'jshashtable': 'vendor/jshashtable-2.1',
'jquery.numberformatter': 'vendor/jquery.numberformatter-1.2.3.min',
'jq-datepicker': 'vendor/bootstrap-datepicker',
'jq-datepicker.da': 'vendor/bootstrap-datepicker.da'
},
// Use shim for plugins that does not support AMD
shim: {
'bootstrap': ['jquery'],
'select2': ['jquery'],
'jq-datepicker': ['jquery'],
'jshashtable': ['jquery'],
'jquery.numberformatter': ['jquery', 'jshashtable']
},
});
reference : http://requirejs.org/docs/api.html#config-shim
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With