Search code examples
javascriptrequirejsamd

RequireJS is not loading modules relative to the baseUrl


In the <head> tag

<script>
var require = {
    baseUrl: '/dist/js',
    paths: {
        jquery: 'jquery-1.11.3'
    }
};
</script>
<script data-main="main.js" src="/dist/js/require.js></script>

And in main.js:

define(["exports", "jquery", "order.js", "search.js"], function (exports, _jquery, _orderJs, _searchJs) {
  "use strict";

  console.log("Hello");
});

Now, main.js loads just fine, same with jquery. But order.js and search.js is being loaded from the root (http://example.com/order.js). Why is it not loading from the baseUrl?


Solution

  • Remove the .js extension from the module names you give to define or require. If you put the extension yourself, then RequireJS assumes the module name is a literal path and will skip your configuration.