1

Actually I'm facing an irritating problem with Requirejs and Backbone. I'm developing my App on two different paths:

  1. the main access, for example: /App/index.php#list
  2. the sub access, for example: /App/index.php/clone#list

The problem appear when I need to load a module with the method require([module]).

If I use the absolute path, like require(['/App/js/views/modal.js']) I just obtain this error:

Error: Load timeout for modules: /App/js/views/modal.js

http://requirejs.org/docs/errors.html#timeout

If I use a relative way, like require(['js/views/modal.js']) on my main access and require(['../js/views/modal.js']) on my sub access, everything work as expected.

I'm loading other modules with the absolute path and they work, if I duplicate the module and require it with a different name it works, I tink the only difference is that the module I'm requiring has already been definited in another module and so it has already been loaded, like this:

Main module

require('/App/js/views/row.js'], function(Row){
     Somecode...
});

....

require('/App/js/views/modal.js'], function(Modal){
     Othercode...
});

Row Module

define([
'backbone',
'text!templates/row.html',
'views/modal', //the same view callend in my main file!
], function(Backbone, rowTemplate, Modal){
    Viewcode...
});

Modal Module

define([
'backbone',
'text!templates/modal.html',
'models/user_model',
], function(Backbone, modalTemplate, Model){
    Viewcode...
});

Maybe I'm missing something but I don't get the logic behind this, why isn't working with the absolute address?

1 Answer 1

1

You don't need to append .js on to the end of filenames in require.js, and I have seen odd behaviour in doing so myself. Also I'd advise you within the various modules of your application to use relative paths as it makes dragging and dropping modules / components of your app into another application more straightforward.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the advices, I've "fixed" this with a little workaround, by making the main access looks the same as the secondary (/App/index.php/main#list), so I can just use relative paths.
So it was a misconfiguration in the paths or baseUrl config parameter? Please mark the correct answer then or create your own answer and mark it. Just don't let this question hanging like this.

Your Answer

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.