node version: v18.12.1 @google-cloud/bigquery version: v6.0.3
I am using a service account to to connect to bigQuery, then trying to run a simple query. Query is working fine on google console but for some reason I am facing issues while running it with nodejs
const authFile = require("./enums/authFile.json");
const { BigQuery } = require("@google-cloud/bigquery");
const queryDb = new BigQuery({
keyFilename: authFile,
projectId: "projectId"
});
const result = await queryDb.createDataset("new_1datasetId", { location: "US" });
I am getting this error for every kind of query I try to run. Even when I try to create a queryJob with
const [job] = await bigquery.createQueryJob(options);
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Object
at new NodeError (node:internal/errors:393:5)
at validateString (node:internal/validators:163:11)
at Object.resolve (node:path:1098:7)
at GoogleAuth.getClient (/usr/src/app/node_modules/google-auth-library/build/src/auth/googleauth.js:633:39)
at GoogleAuth.authorizeRequest (/usr/src/app/node_modules/google-auth-library/build/src/auth/googleauth.js:679:35)
at authorizeRequest (/usr/src/app/node_modules/@google-cloud/common/build/src/util.js:439:47)
at prepareRequest (/usr/src/app/node_modules/@google-cloud/common/build/src/util.js:444:25)
at BigQuery.makeAuthenticatedRequest (/usr/src/app/node_modules/@google-cloud/common/build/src/util.js:455:13)
at BigQuery.request_ (/usr/src/app/node_modules/@google-cloud/common/build/src/service.js:148:18)
at BigQuery.request (/usr/src/app/node_modules/@google-cloud/common/build/src/service.js:159:36)
at BigQuery.createDataset (/usr/src/app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:902:14)
at /usr/src/app/node_modules/@google-cloud/promisify/build/src/index.js:57:28
at new Promise (<anonymous>)
at BigQuery.wrapper (/usr/src/app/node_modules/@google-cloud/promisify/build/src/index.js:42:16)
at checkAlert (/usr/src/app/src/helpers/echo.js:131:34)
at /usr/src/app/src/helpers/echo.js:118:9 {
code: 'ERR_INVALID_ARG_TYPE'
Your authFile
is a module. The constructor expects a path to the file itself .
const queryDb = new BigQuery({
keyFilename: "./enums/authFile.json",
projectId: "projectId"
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.