title: Loading modules in TypeScript using System.js
body: <p>I have a Node.js &amp; AngularJS app written in TypeScript, in which I'm trying to load modules using System.js.</p>
  
  <p>It works fine if I only import a class to specify a type. e.g:</p>
  
  <pre><code>import {BlogModel} from  "./model"
  var model: BlogModel;
  </code></pre>
  
  <p>However, when I try to instantiate a variable with an imported class, I get an exception at run-time. e.g:</p>
  
  <pre><code>import {BlogModel} from  "./model"
  var model: BlogModel = new BlogModel();
  </code></pre>
  
  <blockquote>
    <p>Uncaught ReferenceError: require is not defined</p>
  </blockquote>
  
  <p>I use CommonJS. I cannot use AMD because I have one project for both server side and client side. This is why I use System.js to load modules in the client.</p>
  
  <p>This is my System.js definition:</p>
  
  <pre><code> &lt;script src="/assets/libs/systemjs-master/dist/system-polyfills.js"&gt;&lt;/script&gt;
      &lt;script src="/assets/libs/systemjs-master/dist/system.src.js"&gt;&lt;/script&gt;
  
      &lt;script&gt;
          System.config({
              packages: {
                  app: {
                      format: 'register',
                      defaultExtension: 'js'
                  }
              }
          });
          System.import('classes.ts')
                  .then(null, console.error.bind(console));
          System.import('model.ts')
                  .then(null, console.error.bind(console));
      &lt;/script&gt;
  </code></pre>
  
  <p>This is the content of model.ts file:</p>
  
  <pre><code>import {User} from "./classes";
  import {Post} from "./classes";
  
  export class BlogModel{
      private _currentUser: User;
      private _posts: Post[];
  
      get currentUser(){
          return this._currentUser;
      }
  
      set currentUser(value: User){
          this._currentUser = value;
      }
  
      get posts(){
          return this._posts;
      }
  
      set posts(value: Post[]){
          this._posts = value;
      }
  }
  </code></pre>
  
  <p>And this is the JS line that produces the exception:</p>
  
  <pre><code>var model_1 = require("./model");
  </code></pre>
  
  <blockquote>
    <p>Uncaught ReferenceError: require is not defined</p>
  </blockquote>
  
  <p>Any help will be profoundly appreciated! </p>