title: Cloud Function: TypeError: Cannot read property 'auth' of undefined
body: <p>I am using Google Cloud Functions and wrote a function in the console. But I keep getting this error:</p>
  
  <p><strong>TypeError: Cannot read property 'auth' of undefined</strong></p>
  
  <p>Here is my index.js</p>
  
  <pre><code>var {google} = require('googleapis');
  const { auth } = require('google-auth-library');
  
  exports.goWithTheDataFlow  = (event, callback) =&gt; {
  
  
  const file = event.data;
    const context = event.context;
  
    console.log(`Event ${context.eventId}`);
    console.log(`  Event Type: ${context.eventType}`);
    console.log(`  Bucket: ${file.bucket}`);
    console.log(`  File: ${file.name}`);
    console.log(`  Metageneration: ${file.metageneration}`);
    console.log(`  Created: ${file.timeCreated}`);
    console.log(`  Updated: ${file.updated}`);
  
    google.auth.getApplicationDefault(function (err, authClient, projectId) {
       if (err) {
         throw err;
       }
  
   console.log(projectId);
  
   const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });
          console.log(`gs://${file.bucket}/${file.name}`);
   dataflow.projects.templates.create({
     projectId: projectId,
     resource: {
       parameters: {
         inputFile: `gs://${file.bucket}/${file.name}`
  
       },
       jobName: 'cloud-fn-beam-test',
       gcsPath: 'gs://goldsgymdemo/templates/MyGCStoBQDFTemplate'
     }
   }, function(err, response) {
     if (err) {
       console.error("problem running dataflow template, error was: ", err);
     }
     console.log("Dataflow template response: ", response);
     callback();
   });
  
     });
  
   callback();
  };
  </code></pre>
  
  <p>Here is my package.json.</p>
  
  <pre><code>{
    "name": "sample-cloud-storage",
    "version": "0.0.1",
      "dependencies": {
      "googleapis": "^21.3.0",
      "google-auth-library":  "^1.6.0" 
    }
  }
  </code></pre>
  
  <p>I have created this function directly in the Google Cloud Functions Console UI.
  I am trying to follow the example here but I believe this was built locally. Whereas I am trying to use the Google Cloud Functions Console UI directly instead. Because I am already in GCP and writing this function in the Console UI - do I need to authenticate? Shouldn't it pick up the user credentials &amp; project id directly?</p>
  
  <p><a href="https://stackoverflow.com/questions/50689894/cloud-functions-detailed-stack-trace-error-cannot-find-module-googleapis/50702169#50702169">Cloud Functions: Detailed stack trace: Error: Cannot find module &#39;googleapis&#39;</a></p>
  
  <p>Thanks!</p>