Cloud Function: TypeError: Cannot read property 'auth' of undefined

Cloud Function: TypeError: Cannot read property 'auth' of undefined

我正在使用 Google Cloud Functions 并在控制台中编写了一个函数。但我不断收到此错误:

TypeError: 无法读取未定义的 属性 'auth'

这是我的 index.js

var {google} = require('googleapis');
const { auth } = require('google-auth-library');

exports.goWithTheDataFlow  = (event, callback) => {


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();
};

这是我的package.json。

{
  "name": "sample-cloud-storage",
  "version": "0.0.1",
    "dependencies": {
    "googleapis": "^21.3.0",
    "google-auth-library":  "^1.6.0" 
  }
}

我直接在 Google 云函数控制台 UI 中创建了这个函数。 我正在尝试按照此处的示例进行操作,但我相信这是在本地构建的。而我正在尝试直接使用 Google Cloud Functions Console UI。因为我已经在 GCP 中并在控制台中编写此函数 UI - 我需要进行身份验证吗?它不应该直接获取用户凭据和项目 ID 吗?

谢谢!

我刚刚进行了快速测试,并能够通过使用

使其正常工作
const google = require('googleapis'); 

并删除

const { auth } = require('google-auth-library');

此外,我使用了以下package.json

{
  "name": "sample-cloud-storage",
  "version": "0.0.1",
  "dependencies": {
    "googleapis": "24.0.0"
  }
}