title: RequireJS randomly loads wrong filename with AMD modules
body: <p>I have my config (main.js) defined as:</p>
  
  <pre><code>require.config({
      urlArgs: "bust=" + (new Date()).getTime(),
      paths: {
          jquery: 'jquery-1.8.3.min',
          knockout: 'knockout-2.2.0',
          komapping: 'knockout.mapping-latest',
          token: 'jquery.tokeninput'
      },
      shim: {
          'token': ['jquery']
      }
  });
  </code></pre>
  
  <p><strong>EDIT</strong>
  main.js is a shared configuration. I have several pages that all use the same setup and I don't want to need to modify version-specific filenames all over the place in my project.
  <strong>/EDIT</strong></p>
  
  <p>and included in the page as:</p>
  
  <pre><code>&lt;script src="/AnswersDev/Scripts/require.js" data-main="/AnswersDev/Scripts/main"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>add-report.js is included as:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      require(['Views/add-report']);
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>EDIT</strong>
  That appears likely to be the cause. The inline script is sometimes running before main, and therefore the aliases it is expecting to find are not defined, so it just goes looking for .js.
  <strong>/EDIT</strong></p>
  
  <p>jquery.tokeninput is AFAIK, the only non-AMD module I'm using. A working request results in the following sequence of request (Fiddler capture):</p>
  
  <ol>
  <li>require.js </li>
  <li>main.js </li>
  <li>Views/add-report.js</li>
  <li>Views/add-report-wizard-model.js </li>
  <li>knockout-2.2.0 </li>
  <li>jquery-1.8.3.min.js</li>
  <li>Views/add-report-wizard-model-parameter.js</li>
  <li>Views/add-report-wizard-model-step.js </li>
  <li>knockout.mapping-latest.js</li>
  </ol>
  
  <p>A non-working request has a sequence like e.g.:</p>
  
  <ol>
  <li>require.js</li>
  <li><em>Views/add-report.js</em></li>
  <li><em>main.js</em></li>
  <li>Views/add-report-wizard-model.js</li>
  <li><strong>knockout.js</strong></li>
  <li><strong>jquery.js</strong></li>
  <li>Views/add-report-wizard-model-step.js</li>
  <li>Views/add-report-wizard-model-parameter.js</li>
  <li>knockout.mapping-latest.js</li>
  </ol>
  
  <p>add-report.js:</p>
  
  <pre><code>define(['jquery', 'knockout', 'Views/add-report-wizard-model'], function ($, ko, ViewModel) {
  ... snip ...
  });
  </code></pre>
  
  <p>Note that in the non-working sequence, add-report.js is requested <strong>before</strong> require.js (I expected that non-deterministic load order applied <strong>after</strong> require.js is loaded) and both knockout and jquery (both having AMD support built in) are being requested with the wrong file names. I have observed other sequences where require is requested before add-report and the knockout and jquery file names are still wrong. The only thing I am doing between requests is refreshing the browser (I'll also note that once it works, it tends to keep working, and once it breaks, it tends to stay broken). I've tried removing <code>urlArgs</code> from the config and still observe the same issue. On this particular page, jquery.tokeninput is not used. Removing it from the config file does not appear to have any effect either.</p>
  
  <p>At this point, RequireJS is completely unreliable for me and I certainly cannot release my code to production in the current state. Given the number of people who seem to be using RequireJS quite successfully, I can only assume that the problem is in my code somewhere, but I'm at a loss as to where that might be.</p>
  
  <p>Anyone have any suggestions where I might have gone wrong? Thanks.</p>
  
  <p>EDIT: As requested, excerpt from knockout.mapping-latest.debug.js:</p>
  
  <pre><code>// Module systems magic dance.
  
  if (typeof require === "function" &amp;&amp; typeof exports === "object" &amp;&amp; typeof module === "object") {
      // CommonJS or Node: hard-coded dependency on "knockout"
      factory(require("knockout"), exports);
  } else if (typeof define === "function" &amp;&amp; define["amd"]) {
      // AMD anonymous module with hard-coded dependency on "knockout"
      define(["knockout", "exports"], factory);
  } else {
      // &lt;script&gt; tag: use the global `ko` object, attaching a `mapping` property
      factory(ko, ko.mapping = {});
  }
  </code></pre>