title: Undefined object being passed via Requirejs
body: <p>I'm using <code>Requirejs</code> to load the JavaScript in our web app. The issues is that I'm getting an <code>undefined</code> object being passed to a module which, when used in other modules, is instantiated perfectly fine.</p>
  
  <p>OK, here's the setup. My <code>main.js</code> file which requirejs runs on startup:</p>
  
  <pre><code>require.config({
      baseUrl: "/scripts",
      paths: {
          demographics: "Demographics/demographics",
          complaints: "Complaints/complaints",
      }
  });
  
  require(["templates", "demographics", "complaints", "crossDomain"], function (templates, demographics, complaints) {
      "use strict";
  
      console.log("0");
      console.log(demographics === undefined);
  
      demographics.View.display();
  });
  </code></pre>
  
  <p>A lot of the config has been stripped to just the core files in this problem.</p>
  
  <p>Here's <code>Demographics.js</code>:</p>
  
  <pre><code>define(["ko", "templates", "complaints", "globals", "underscore"], function (ko, templates, complaints, globals) {
  
      // Stuff removed.
      return {
          View: view
      };
  });
  </code></pre>
  
  <p>and <code>Complaints.js</code></p>
  
  <pre><code>define([
      "demographics",
      "ko",
      "templates",
      "complaints",
      "visualeffects",
      "globals",
      "webservice",
      "underscore",
      "typewatcher",
      "imagesloaded"],
      function (demographics, ko, templates, complaints, visualeffects, globals, webservice) {
          "use strict";
  
  
          console.log("1");
          console.log(demographics === undefined);
      return {
          View: view
      };
  });
  </code></pre>
  
  <p>The problem is this - in <code>Complaints.js</code> the <code>demographics</code> parameter passed via the <code>define</code> config is <code>undefined</code>. The console log out tells me that "demographics === undefined" is <code>true</code>.</p>
  
  <p>However, when the main.js file executes, the demographics parameter passed to it is not undefined, it is, as expected, an instantiated object.</p>
  
  <p>Now I'm stuck since I can't see why in <code>complaints.js</code> that demographics variable is undefined. Can anyone spot what I'm missing please?</p>