title: NodeJS - Google API Module - [TypeError: Cannot read property 'prototype' of undefined]
body: <p>I installed the nodejs module "googleapis" (<code>npm install googleapis</code>) to an Azure Mobile Services instance and I wanted to do a quick test with some sample code I found here <a href="https://www.npmjs.org/package/googleapis" rel="nofollow">https://www.npmjs.org/package/googleapis</a>. After trying the code sample which creates a text file in google drive I get the following error message in the console:</p>
  
  <pre><code>[TypeError: Cannot read property 'prototype' of undefined]
  </code></pre>
  
  <p>The error is occurring at line 40 of the current version of  google-api-nodejs-client / apis / index.js (<a href="https://github.com/google/google-api-nodejs-client/blob/master/apis/index.js" rel="nofollow">https://github.com/google/google-api-nodejs-client/blob/master/apis/index.js</a>):</p>
  
  <pre><code>var Endpoint = require(__dirname + '/' + filename + '/' + path.basename(version));
  </code></pre>
  
  <p>When debugging I can see the path used in the above method as the following:    </p>
  
  <pre><code>D:\home\site\wwwroot\App_Data\config\scripts\node_modules\googleapis\apis\drive\v2
  </code></pre>
  
  <p>I have verified that the path is correct.</p>
  
  <p>Here is the code I tried to run:</p>
  
  <pre><code>var google = require('googleapis');
  
  var OAuth2Client = google.auth.OAuth2;
  var CLIENT_ID = 'xxxx';
  var CLIENT_SECRET = 'xxxxxx';
  var REDIRECT_URL = 'xxxxx';
  var oauth2Client = new OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);
  oauth2Client.setCredentials({
  access_token: identities.google.accessToken
  });
  
  var drive = google.drive({ version: 'v2', auth: oauth2Client });
  
  drive.files.insert({
    resource: {
      title: 'Test',
      mimeType: 'text/plain'
    },
    media: {
      mimeType: 'text/plain',
      body: 'Hello World'
    }
  }, function(err, response) {
  console.log('error:', err, 'inserted:', response.id);
  });
  </code></pre>
  
  <p>What is the source of the issue?</p>
  
  <p>Here is the error stack trace:</p>
  
  <pre><code>TypeError: Cannot read property 'prototype' of undefined at Object.&lt;anonymous&gt; 
  (D:\home\site\wwwroot\App_Data\config\scripts\node_modules\googleapis\node_modules\multipart-stream\node_modules\sandwich-stream\lib\sandwich-stream.js:24:50) 
      at Module._compile (module.js:449:26) 
      at Object.Module._extensions..js (module.js:467:10) 
      at Module.load (module.js:356:32) 
      at Function.Module._load (module.js:312:12) 
      at Module.require (module.js:362:17) 
      at require (module.js:378:17) 
      at Object.&lt;anonymous&gt; (D:\home\site\wwwroot\App_Data\config\scripts\node_modules\googleapis\node_modules\multipart-stream\index.js:1:78) 
      at Module._compile (module.js:449:26) 
      at Object.Module._extensions..js (module.js:467:10)
  </code></pre>
  
  <p>Here is line 24 of sandwich-stream.js:</p>
  
  <pre><code>SandwichStream.prototype = Object.create(Readable.prototype, {
    constructor: SandwichStream
  });
  </code></pre>
  
  <p>The nodejs version is:</p>
  
  <pre><code>Node version: v0.8.28
  </code></pre>