title: Cloud Functions: Detailed stack trace: Error: Cannot find module 'googleapis'
body: <p>This is related to these 2 threads:
  <a href="https://stackoverflow.com/questions/49348220/google-cloud-functions-cannot-read-property-getapplicationdefault">Google cloud functions - cannot read property &#39;getApplicationDefault&#39;</a>
  <a href="https://stackoverflow.com/questions/49379756/triggering-cloud-dataflow-pipeline-from-cloud-function-function-times-out">Triggering Cloud Dataflow pipeline from Cloud Function - function times out</a></p>
  
  <p>I have created a dataflow template that will copy data from GCS to BigQuery as these two examples. </p>
  
  <p>As part of the initialization process, I run</p>
  
  <pre><code>npm init
  npm install --save googleapis
  </code></pre>
  
  <p>Here is my index.js</p>
  
  <pre><code>    var {google} = require('googleapis');
  
  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>And here is my package.json (after I have run npm init &amp; npm install --save googleapis)</p>
  
  <pre><code>{
    "name": "sample-cloud-storage",
    "version": "0.0.1"
  }
  </code></pre>
  
  <p>When I run this function with function: goWithTheDataFlow &amp; Trigger: </p>
  
  <p>I get an error:</p>
  
  <pre><code>Deployment failure:
  Function load error: Code in file index.js can't be loaded.
  Did you list all required modules in the package.json dependencies?
  Detailed stack trace: Error: Cannot find module 'googleapis'
      at Function.Module._resolveFilename (module.js:476:15)
      at Function.Module._load (module.js:424:25)
      at Module.require (module.js:504:17)
      at require (internal/module.js:20:19)
      at Object.&lt;anonymous&gt; (/user_code/index.js:1:78)
      at Module._compile (module.js:577:32)
      at Object.Module._extensions..js (module.js:586:10)
      at Module.load (module.js:494:32)
      at tryModuleLoad (module.js:453:12)
      at Function.Module._load (module.js:445:3)
  </code></pre>
  
  <p>Can you please help? What am I missing?
  Thx</p>