title: RequireJS out-of-order execution - not honouring arguments to `require`
body: <p>When building and running RequireJS with CoffeeScript in what I understand to be the ordinary way, I seem to have a problem with code not being executed in the expected order i.e.</p>
  
  <pre><code>&lt;script src="/_s/lib/require-jquery.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    require.config({
      paths: {
        "main": "/_s/all.min", // &lt;--- the 'optimized' result of `$ r.js build.js`
      }
    });
    require(["main"], function () {
       // this executes without any regard to whether 'main' is loaded.
       // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       // also:
       // require('cs!csmain') throws an exception because "cs!csmain" has not been
       // loaded for context: '_'.
    });
  </code></pre>
  
  <p></p>
  
  <p>One would expect the function passed to <code>require(["main"], ...</code> to be executed after main and all its dependencies are loaded, because <a href="http://requirejs.org/docs/api.html#config" rel="nofollow">that's what the documentation says</a>.</p>
  
  <p>However, that is not the case at all. On my local development system this problem does not exhibit itself, I suppose because it is a race condition of some sort, making it doubly problematic because this is cropping up only AFTER deployment/staging.</p>
  
  <p>I have a straightforward <code>main.js</code> like this:</p>
  
  <pre><code>var _paths;
  
  _paths = {
    ... 
    underscore: '../lib/lodash'
  };
  
  require.config({
    baseUrl: '/_s/mycode/', // main.js lives here
    paths: _paths,
    shim: {
       ...
      'timeago': ['jquery']
    },
    waitSeconds: 60
  });
  
  require(['cs!csmain']); // has all the dependencies
  </code></pre>
  
  <p>Along with a <code>build.js</code> called as an argument to <code>r.js</code> along the lines of:</p>
  
  <pre><code>({
      baseUrl:    'mycode',
      optimize:   'none',
      out:        'all.min.js',
      stubModules: ['cs', 'coffee-script'],
      paths: {
          ...
          underscore: '../lib/lodash'
      },
      name: 'main',
      shim: {
         ...
      }
  })
  </code></pre>
  
  <p>Does anyone have any idea what's going on here? I really enjoy the asynchronous nature of RequireJS combined with the ability to split up my code into sensible modules, but this problem is particularly frustrating because it only exhibits on a staging/production setting.</p>
  
  <p>Any thoughts and suggestions would be duly appreciated.</p>
  
  <p><strong>EDIT</strong>: Removed some probably-superfluous arguments to shorten the question.</p>