When I attempt to run the code below, I encounter an error that says "Cannot read property 'fn' of undefined" due to jquery not being found.
requirejs.config({
baseUrl: "/static/javascript",
paths: {
jquery: "vendor/jquery",
underscore: "vendor/underscore"
},
shim: {
underscore: {
exports: "_"
}
} });
require(["underscore","jquery"],function(un){
console.log("jQuery version: ", $.fn.jquery);
console.log("underscore identity call: ", _.identity(5));
console.log("underscore identity call: ", un.identity(5));
});
Strangely enough, modifying the code like this allows it to work:
requirejs.config({
paths: {
jquery: "vendor/jquery",
underscore: "vendor/underscore"
},
shim: {
underscore: {
exports: "_"
}
} });
require(["underscore","vendor/jquery"],function(un){
console.log("jQuery version: ", $.fn.jquery);
console.log("underscore identity call: ", _.identity(5));
console.log("underscore identity call: ", un.identity(5));
});
Surprisingly, this change solved the issue. Despite both codes having the same path, my system seems to have trouble with the baseURL. What could be causing this and what is wrong with the initial code?