title: requirejs firing callbacks before dependencies are loaded - sometimes
body: <p>I have a requirejs app that is not loading consistently. Typically it works as long as I'm on a cached set of content but that's not a big surprise. However clearing cache almost always causes scripts to not be present.</p>
  
  <p>I'm not including dependencies outside of my application - everything is included via define() dependency injection.</p>
  
  <p>My main.js file contains the following, which is launched using data-main per requirejs standards:</p>
  
  <pre><code>require.config({
      baseUrl: "script/module",
      paths: {
          "signals": "vendor/signals"
      }
  });
  
  require(["mainController"], function(){
      console.log("Full dependency tree load complete");
  });
  </code></pre>
  
  <p>My main controller contains the following:</p>
  
  <pre><code>define(
      ["vendor/preloadjs", "router"],
      function (createjs, router) {
          //At this point all controllers are loaded and ready to go
          console.log("main controller"); //This successfully fires every time
          return {};
      }
  );
  </code></pre>
  
  <p>The problem lies in router.js:</p>
  
  <pre><code>define(
      ["vendor/crossroads", "vendor/hasher"],
      function(xr, h) {
          console.log(xr, h);
          return {};
      }
  );
  </code></pre>
  
  <p>The log in this file will <em>usually</em> output the correct object for crossroads (xr in this case), and <em>sometimes</em> will output the correct object for hasher (h). However 3 or 4 times out of ten (when refreshing with a cache) and 10 times out of 10 when refreshing without cached content, it breaks. And it doesn't break consistently. Sometimes crossroads will be undefined, sometimes hasher will be the following object:</p>
  
  <pre><code>{
      noConflict: ()
      parse: parse()
      runInContext: a(b, d)
      stringify: stringify()
      __proto__: Object
  }
  </code></pre>
  
  <p>And sometimes signals.js (a dependency defined for both hasher and crossroads, which is defined in the paths config in the main js file) fails to load and I get other errors such as a.Signal is not defined.</p>
  
  <p>What I'm seeing here is that my callbacks are firing before my dependencies have loaded. All three of these dependencies are amd/require enabled, and they work "some" of the time. Isn't the entire point of require.js to NOT fire callbacks before the dependency tree is loaded? What am I missing?</p>
  
  <p>Thanks!!!</p>