Skip to content

Module instancing problem with storage+bigquery.import #1516

Description

@jakeorr

Hi,

I am trying to switch to the new method of requiring only the modules that I need instead of the entire google-cloud module. I'm running into a problem importing files from cloud storage into bigquery. This was working until I switched to requiring separate modules.

const bigQuery = require('@google-cloud/bigquery')({
  projectId: [projectId],
  client_email: [email],
  private_key: [key string]
});

const gcs = require('@google-cloud/storage')({
  projectId: [projectId],
  client_email: [email],
  private_key: [key string]
});

var file = gcs.bucket([bucket name]).file('afile.csv');

// This debug output prints "true"
console.log(file instanceof require("@google-cloud/storage").File);

bigQuery
  .dataset([dataset ID])
  .table([table ID])
  .import([file], next);

The import call fails with:

Error: Source must be a File object.
    at /[project dir]/node_modules/@google-cloud/bigquery/src/table.js:809:15

Adding a debug prop to require('@google-cloud/storage'), it looks like my app and the bigquery modules have two different instances of the storage module, causing instanceof to report the files passed as being the wrong type.

Environment details

  • OS: OSX 10.11.6
  • Node.js version: v4.4.4
  • npm version: 2.15.1
  • gcloud-node version: v0.1.1 for both /bigquery and /storage

This seems like a bug, but I could be missing something. Any help would be appreciated, thanks!

Activity

  1. stephenplusplus commented on Aug 22, 2016

    @stephenplusplus
    Contributor

    :\ Sorry about that. This is because of the way we type check for custom types. We have an issue that is suggesting a better way to do that, which would fix this at the same time. I'm going to assign that one to myself and start on it tomorrow so that hopefully we can release a fix shortly.

    Closing only because #1467 will track the fix.

  2. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Aug 22, 2016
  3. jakeorr commented on Aug 22, 2016

    @jakeorr
    Author

    Excellent, thanks Stephen! For now I'm just using the entire google-cloud package so things are still working 👍

  4. stephenplusplus commented on Aug 22, 2016

    @stephenplusplus
    Contributor

    Phew 😌 Thanks for being patient with the bumps from the modularization releases!

  5. erdillon commented on Sep 19, 2017

    @erdillon

    Hi there. I'm running into the same issue. Is that no fixed?

  6. stephenplusplus commented on Sep 21, 2017

    @stephenplusplus
    Contributor

    @erdillon can you open a new issue, including steps to reproduce and environment information?

  7. added a commit that references this issue on Jul 23, 2025
  8. added a commit that references this issue on Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api: bigqueryIssues related to the BigQuery API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions