Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery is not a constructor Error when connecting to Google BigQuery with Nodejs

According to all the tutorials I found (one example in the link below) the following snippet should allow me to connect and query Google BigQuery. But whatever combination of sending credential jsons, or not, always results in the same error "BigQuery is not a constructor" I am currently testing this through the google online cloud shell. Any ideas would be helpful. Thanks 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();
  });

Error

/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
like image 613
lukechambers91 Avatar asked Nov 07 '18 14:11

lukechambers91


People also ask

How do I access BigQuery in GCP?

Find BigQuery in the left side menu of the Google Cloud Platform Console, under Big Data. Open your project in the console. If you're new to the console, you may need to sign up for a Google account, access the console, and create a project. Find BigQuery in the left side menu of the console, under Big Data.


1 Answers

This issue seems to be generated as it is required to add the { } symbols to the BigQuery import. I have just made a test by adding the following import line and it worked perfectly:

// Imports the Google Cloud client library
const {BigQuery} = require('@google-cloud/bigquery');
like image 200
Armin_SC Avatar answered Oct 12 '22 20:10

Armin_SC