title: How to add SockJS into Angular 2 project?
body: <p>I use angular-cli to generate a new project. Now I want to add socketJs to the project, but keep getting errors in browser console:</p>
  
  <pre><code>GET http://localhost:4200/url-parse 404 (Not Found)
  GET http://localhost:4200/inherits 404 (Not Found)
  Unhandled Promise rejection: Error: XHR error (404 Not Found) loading http://localhost:4200/url-parse
          at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:4200/vendor/zone.js/dist/zone.js:769:30)
          at ZoneDelegate.invokeTask (http://localhost:4200/vendor/zone.js/dist/zone.js:356:38)
          at Zone.runTask (http://localhost:4200/vendor/zone.js/dist/zone.js:256:48)
          at XMLHttpRequest.ZoneTask.invoke (http://localhost:4200/vendor/zone.js/dist/zone.js:423:34)
      Error loading http://localhost:4200/url-parse as "url-parse" from http://localhost:4200/vendor/sockjs-client/lib/main.js ; Zone: &lt;root&gt; ; Task: Promise.then ; Value: Error: Error: XHR error (404 Not Found) loading http://localhost:4200/url-parse(…)
  Error: Uncaught (in promise): Error: Error: XHR error (404 Not Found) loading http://localhost:4200/url-parse(…)
  GET http://localhost:4200/json3 404 (Not Found)
  GET http://localhost:4200/debug 404 (Not Found)
  GET http://localhost:4200/events 404 (Not Found)
  GET http://localhost:4200/eventsource 404 (Not Found)
  GET http://localhost:4200/crypto 404 (Not Found)
  GET http://localhost:4200/json3 404 (Not Found)
  GET http://localhost:4200/url-parse 404 (Not Found)
  GET http://localhost:4200/debug 404 (Not Found)
  GET http://localhost:4200/inherits 404 (Not Found)
  Assertion failed: loading or loaded
  GET http://localhost:4200/events 404 (Not Found)
  Assertion failed: loading or loaded
  GET http://localhost:4200/faye-websocket 404 (Not Found)
  Assertion failed: loading or loaded
  GET http://localhost:4200/eventsource 404 (Not Found)
  Assertion failed: loading or loaded
  GET http://localhost:4200/http 404 (Not Found)
  GET http://localhost:4200/https 404 (Not Found)
  </code></pre>
  
  <p>This is my steps and configuration:</p>
  
  <pre><code>typings install sockjs-client --save --ambient
  </code></pre>
  
  <p>angular-cli-build.js</p>
  
  <pre><code>var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
  
  module.exports = function(defaults) {
    return new Angular2App(defaults, {
      vendorNpmFiles: [
        'systemjs/dist/system-polyfills.js',
        'systemjs/dist/system.src.js',
        'zone.js/dist/**/*.+(js|js.map)',
        'es6-shim/es6-shim.js',
        'reflect-metadata/**/*.+(ts|js|js.map)',
        'rxjs/**/*.+(js|js.map)',
        '@angular/**/*.+(js|js.map)',
        'sockjs-client/**/*.+(js)'
      ]
    });
  };
  </code></pre>
  
  <p>system-config.ts</p>
  
  <pre><code>/** Map relative paths to URLs. */
  const map: any = {
    'sockjs-client': 'vendor/sockjs-client/lib/entry.js'
  };
  
  /** User packages configuration. */
  const packages: any = {
    'vendor/sockjs-client/lib': {
      'format': 'cjs',
      'defaultExtension': 'js'
    }
  };
  </code></pre>
  
  <p>My custom service class:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  
  import * as SockJS from 'sockjs-client';
  import BaseEvent = __SockJSClient.BaseEvent;
  import SockJSClass = __SockJSClient.SockJSClass;
  
  @Injectable()
  export class WebsocketService {
  
    private sockJs: SockJSClass;
  
    constructor() {
      console.log('constuctor');
      this.sockJs = new SockJS('/hello');
    }
  }
  </code></pre>
  
  <p>Please let me know how to fix it, thanks a lot!</p>
  
  <p>I can, however, eliminate some error by including the missing lib by adding them one by one in system-config.ts. But I doubt this is the right approach.</p>
  
  <pre><code>const map: any = {
    'sockjs-client': 'vendor/sockjs-client/lib/entry.js',
    'json3': 'vendor/sockjs-client/node_modules/json3/lib/json3.js',
    'url-parse': 'vendor/sockjs-client/node_modules/url-parse/index.js',
    'inherits': 'vendor/sockjs-client/node_modules/inherits/inherits.js',
    'debug': 'vendor/sockjs-client/node_modules/debug/debug.js',
    ...
  };
  </code></pre>