question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vision is not a constructor

See original GitHub issue

I’m using the current release, and tried:

const {Vision} = require('@google-cloud/vision');

const token = {} //json for the google application credential

const vision = new Vision(token);

But it yields error that vision is not a constructor. What am I missing?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-fenstercommented, Jul 20, 2020

@bcoe @JustinBeckwith FYI - the codelab example is out of date

1reaction
bpkennedycommented, Nov 18, 2018

Ah, I inspected the ImageAnnotatorClient export and see where the credential can be passed in as an option of that class constructor:

  /**
   * Construct an instance of ImageAnnotatorClient.
   *
   * @param {object} [options] - The configuration object. See the subsequent
   *   parameters for more details.
   * @param {object} [options.credentials] - Credentials object.
   * @param {string} [options.credentials.client_email]
   * @param {string} [options.credentials.private_key]
   * @param {string} [options.email] - Account email address. Required when
   *     using a .pem or .p12 keyFilename.
   * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
   *     .p12 key downloaded from the Google Developers Console. If you provide
   *     a path to a JSON file, the projectId option below is not necessary.
   *     NOTE: .pem and .p12 require you to specify options.email as well.
   * @param {number} [options.port] - The port on which to connect to
   *     the remote host.
   * @param {string} [options.projectId] - The project ID from the Google
   *     Developer's Console, e.g. 'grape-spaceship-123'. We will also check
   *     the environment variable GCLOUD_PROJECT for your project ID. If your
   *     app is running in an environment which supports
   *     {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
   *     your project ID will be detected automatically.
   * @param {function} [options.promise] - Custom promise module to use instead
   *     of native Promises.
   * @param {string} [options.servicePath] - The domain name of the
   *     API remote host.
   */

So, I implemented as thus which seems to work fine:

import Vision from '@google-cloud/vision';

new Vision.ImageAnnotatorClient({
    credentials: token
  });

This seems to work fine, but it does go against some documentation I read earlier (see the Passing the path to the service account key in code). It describes:

// Imports the Google Cloud client library.
const {Storage} = require('@google-cloud/storage');

// Instantiates a client. Explicitly use service account credentials by
// specifying the private key file. All clients in google-cloud-node have this
// helper, see https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/docs/authentication.md
const storage = new Storage({
  projectId: 'project-id',
  keyFilename: '/path/to/keyfile.json'
});

Event though it describes the storage API, I took this to mean that vision also exported a “vision” class which accepts a credential object just like storage, but this is not the case and had me confused.

I suggest changing the wording of “All clients in google-cloud-node have this” for clarity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: gax.GoogleProtoFilesRoot is not a ...
I'm trying to use google vision api to recognize the text in image main.js const vision = require("@google-cloud/vision"); // Creates a ...
Read more >
TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >
Script Function JavaScript Source Code and API ...
Constructor. The JavaScript source code must set a "module.exports" equal to a function that represents the constructor of the tool. This function will...
Read more >
Javascript "Not a Constructor" Exception while creating objects
JavaScript : Javascript " Not a Constructor " Exception while creating objects [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] ...
Read more >
ImageUrl Constructors - Custom Vision Prediction
ImageUrl Constructors. Reference. Feedback ... Vision.CustomVision.Prediction.Models. Assembly: Microsoft.Azure.CognitiveServices.Vision.CustomVision.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found