Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequireJS path 'alias' problems

Tags:

requirejs

Getting mighty tired fighting to get requireJS to work in a predictable manner. Its debugging support is underwhelming.

My config.js file as follows:

require.config({

baseUrl: "Scripts",

paths: {
    "jquery": "jquery-2.1.1.min",
    "bootstrap": "bootstrap.min",
    "knockout": "knockout-3.1.0"
},
shim: {
    "bootstrap": {
        deps: ["jquery"],
        exports: "$.fn.popover"
    }
},
enforceDefine: true
});
require(["jquery", "bootstrap"], function ($, bootstrap) {
    console.log("(A) loaded jq + bs");
    if ($)
        console.log("$ is present");
    if (bootstrap)
        console.log("bootstrap is present");
});
//# sourceMappingURL=Config.js.map

JavaScript in the /Scripts folder, which is where Config.js resides. 'jquery' is supposed to alias to a specific version, but when the browser loads it tries to load /Scripts/jquery.js

The aliased file /Scripts/jquery-2.1.1.min.js exists.

The same happens with bootstrap - it loads boostrap.js instead of bootstrap.min.js

I hate the way requireJS has this arcane way of mixing different behaviours into the same path setting, which changes based on string contents.

like image 834
Quango Avatar asked Jun 11 '26 06:06

Quango


1 Answers

This link may help you.. the configuration file is being loaded asynchronously and has not been executed when you first call require()

Check this one Require JS is ignoring my config

like image 192
Priya Avatar answered Jun 19 '26 16:06

Priya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!