使用Nodejs连接到Google BigQuery时,BigQuery不是构造函数错误

luk*_*s91 4 node.js google-bigquery google-cloud-platform

根据我找到的所有教程(下面的链接中的一个示例),以下代码段应该允许我连接和查询Google BigQuery.但无论发送或不发送凭据jsons的任何组合,总是会导致相同的错误"BigQuery不是构造函数"我目前正在通过谷歌在线云外壳测试.任何想法都会有所帮助.谢谢 https://cloud.google.com/nodejs/docs/reference/bigquery/1.3.x/BigQuery#createJob

const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery();

const query = 'SELECT * FROM `random.table` LIMIT 100';

bigquery.createQueryJob(query).then(function(data) {
    var job = data[0];
    var apiResponse = data[1];
    console.log(job.getQueryResults())
    return job.getQueryResults();
  });
Run Code Online (Sandbox Code Playgroud)

错误

/home/v/testServer.js:2
const bigquery = new BigQuery();
                 ^
TypeError: BigQuery is not a constructor
    at Object.<anonymous> (/home/user_name/testServer.js:2:18)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
Run Code Online (Sandbox Code Playgroud)

Arm*_*_SC 11

似乎生成此问题,因为需要将{ }符号添加到BigQuery导入.我刚刚通过添加以下导入行进行了测试,它完美地运行了:

// Imports the Google Cloud client library
const {BigQuery} = require('@google-cloud/bigquery');
Run Code Online (Sandbox Code Playgroud)