title: requirejs() returns undefined when mixing node and amd modules
body: <p>I am trying to write some JS modules which should be usable in both a browser and node.js environment. </p>
  
  <p>To facilitate this I'm writing these modules as <a href="https://github.com/amdjs/amdjs-api/wiki/AMD" rel="nofollow">AMD modules</a>, and using <a href="http://requirejs.org/docs/node.html" rel="nofollow">requirejs in the Node.js environment</a> to provide the <code>define()</code> function as well as the ability to load these modules.</p>
  
  <p>However, I've encountered some behavior I do not understand.</p>
  
  <p>I made a SSCCE that illustrates the problem:</p>
  
  <pre><code>├── bar.js
  ├── node_modules
  │   └── foo
  │       ├── foo.js
  │       ├── index.js
  │       ├── node_modules
  │       │   └── requirejs
  │       │       ├── bin
  │       │       │   └── r.js
  │       │       ├── package.json
  │       │       ├── README.md
  │       │       └── require.js
  │       └── package.json
  └── test.js
  </code></pre>
  
  <p>foo is a node module which wraps the AMD module foo.js</p>
  
  <p>node_modules/foo/foo.js</p>
  
  <pre><code>define([], function() {
      return function() {
          console.log("This is foo!");
      };
  });
  </code></pre>
  
  <p>node_modules/foo/index.js</p>
  
  <pre><code>var requirejs = require('requirejs');
  
  requirejs.config({
      baseUrl: __dirname,
      nodeRequire: require
  });
  
  module.exports = requirejs('foo');
  </code></pre>
  
  <p>bar.js is another AMD module:</p>
  
  <pre><code>define([], function() {
      return function() {
          console.log("This is bar!");
      };
  });
  </code></pre>
  
  <p>test.js is a script that wants to use both foo and bar:</p>
  
  <pre><code>var requirejs=require('requirejs');
  
  requirejs.config(
      {
          baseUrl: __dirname, 
          nodeRequire: require
      }
  );
  
  var foo=require("foo");
  
  foo();
  
  var bar=requirejs("bar");
  
  console.log("bar is:",bar);
  </code></pre>
  
  <p>If I run test.js, I get this:</p>
  
  <pre><code>This is foo!
  bar is: undefined
  /home/harmic/tmp/test_rjs/node_modules/foo/node_modules/requirejs/bin/r.js:393
          throw err;
                ^
  Error: Mismatched anonymous define() module: function () {
          return function() {
                  console.log("This is bar!");
          };
  }
  http://requirejs.org/docs/errors.html#mismatch
      at makeError (/home/harmic/tmp/test_rjs/node_modules/foo/node_modules/requirejs/bin/r.js:418:17)
      at intakeDefines (/home/harmic/tmp/test_rjs/node_modules/foo/node_modules/requirejs/bin/r.js:1501:36)
      at null._onTimeout (/home/harmic/tmp/test_rjs/node_modules/foo/node_modules/requirejs/bin/r.js:1699:25)
      at Timer.listOnTimeout (timers.js:119:15)
  </code></pre>
  
  <p>There are two things that don't make sense to me here.</p>
  
  <ol>
  <li><p>In test.js, the call to <code>requirejs("bar")</code> returns undef. In fact it appears
  that the loading of the module is deferred, as if there were some circular
  dependancy going on, because it is only after it has returned that the
  module definition for bar is being executed.</p></li>
  <li><p>Why does it think this is an anonymous <code>define()</code> ? My use case does not appear
  to meet the criteria in the given URL.</p></li>
  </ol>
  
  <p>To supress the second issue I tried naming the define in bar.js, like this:</p>
  
  <pre><code>define('bar', [], function() {
  ...
  </code></pre>
  
  <p>That works in the sense that the exception is gone, but <code>requirejs("bar")</code> still
  returns undef.</p>
  
  <p>The example is a simplified version of what I am trying to do - basically I will
  have a number of modules, which will contain some common components that can be
  used in browser and in node, and some node specific components that will only
  be used in node. There will be dependancies between the modules. </p>
  
  <p>If there is some better way of doing this then I'm open to that also.</p>