title: Error loading Socket.io with RequireJS
body: <p>I've been trying to load Socket.io into my application using RequireJS but it just keeps giving errors.</p>
  
  <p>Versions used:</p>
  
  <ul>
  <li><strong>NodeJS:</strong> 0.10.17</li>
  <li><strong>Socket.io:</strong> 0.9.16</li>
  <li><strong>Socket.io-client:</strong> 0.9.16</li>
  <li><strong>RequireJS:</strong> 2.1.8</li>
  </ul>
  
  <h2>Solutions tried:</h2>
  
  <ul>
  <li>From: <a href="https://gist.github.com/guerrerocarlos/3651490" rel="nofollow">https://gist.github.com/guerrerocarlos/3651490</a></li>
  </ul>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>require.config({
      shim: {
          'socketio': {
              exports: 'io'
          },
      },
      wrap: false,
      paths: {
          socket: '/socket.io/socket.io',
          jquery: "jquery-2.0.3.min",
          // Other dependencies
      }
  });
  require(["open_rpg"],function(OpenRPG){
      // App code here
  });
  </code></pre>
  
  <p><strong>file.js</strong></p>
  
  <pre><code>define(["socket"],
      function(io){
          // Socket started here
  </code></pre>
  
  <p>Before using RequireJS socket was working. The Socket JS file is correctly loaded.</p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Uncaught TypeError: Cannot call method 'push' of undefined
  </code></pre>
  
  <hr>
  
  <ul>
  <li>From: <a href="https://github.com/LearnBoost/socket.io-client/issues/497" rel="nofollow">https://github.com/LearnBoost/socket.io-client/issues/497</a></li>
  </ul>
  
  <p>I tried loading Socket.io as a normal JS script, and using:</p>
  
  <pre><code>paths:
    "socket.io": 'empty:'
  </code></pre>
  
  <p>But that returns:</p>
  
  <pre><code>Uncaught Error: Mismatched anonymous define() module: function () { return io; }
  </code></pre>
  
  <hr>
  
  <p><strong>Update:</strong>
  Since NodeJS keeps a modules cache I have added a modified copy of the Socket.io.js file, with line 107 changed as per solution 2 (See the link), and although this works, it's not a real solution. So I will keep this question open.</p>
  
  <p>I have also tried adding the source of SocketIO as a normal JS file, and removing all references to it in RequireJS, but it still seems to be incompatible. </p>