Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

TypeError: Cannot read property 'ImageAnnotatorClient' of undefined #191

Closed
sandrapavankumar opened this issue Sep 11, 2018 · 7 comments
Closed
Assignees
Labels
api: vision Issues related to the googleapis/nodejs-vision API. type: question Request for information or clarification. Not an issue.

Comments

@sandrapavankumar
Copy link

sandrapavankumar commented Sep 11, 2018

I'm new to nodejs, trying google handwriting text recognition. The error log and code is given below, please suggest me.

function test(){
    const vision = require('@google-cloud/vision').v1p3beta1;
    const fs = require('fs');
    const client = new vision.ImageAnnotatorClient();
    const fileName = `C:/Users/sandr/Downloads/menu.jpg`;

    const request = {
    image: {
        content: fs.readFileSync(fileName),
    },
    feature: {
        languageHints: ['en-t-i0-handwrit'],
    },
    };
    client
    .documentTextDetection(request)
    .then(results => {
        const fullTextAnnotation = results[0].fullTextAnnotation;
        console.log(`Full text: ${fullTextAnnotation.text}`);
    })
    .catch(err => {
        console.error('ERROR:', err);
    });  
}

console.log(test());
    const client = new vision.ImageAnnotatorClient();
                              ^

TypeError: Cannot read property 'ImageAnnotatorClient' of undefined
    at test (D:\Softwares\nodejs-docs-samples-master\nodejs-docs-samples-master\functions\ocr\app\MyApp.js:8:31)
    at Object.<anonymous> (D:\Softwares\nodejs-docs-samples-master\nodejs-docs-samples-master\functions\ocr\app\MyApp.js:34:13)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:279:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)

Environment details

  • OS: Windows 10
  • Node.js version: 10.10.0
  • npm version: 6.4.1
  • @google-cloud/vision version: 0.19.0

Thanks!

@JustinBeckwith
Copy link
Contributor

Greetings! I could be wrong, but I don't think you shouldn't need the .v1p3beta1. Will this work without it?

@sandrapavankumar
Copy link
Author

When I remove .v1p3beta1. and try I get an error "TypeError: vision.ImageAnnotatorClient is not a constructor"

@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Sep 11, 2018
@sandrapavankumar
Copy link
Author

Hi @JustinBeckwith, can you please suggest if this is a bug in vision api.

@stephenplusplus
Copy link
Contributor

I believe you just need to upgrade to the latest version of this library, which is currently 0.22.0.

With that version, this works for me:

const vision = require('@google-cloud/vision')
const client = new vision.ImageAnnotatorClient()

Please let me know if you still have issues after the upgrade.

@stephenplusplus stephenplusplus added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Sep 12, 2018
@sandrapavankumar
Copy link
Author

sandrapavankumar commented Sep 12, 2018

Hi @stephenplusplus , I just tried with the latest version, and facing new errors. Kindly suggest me if anything wrong in code.
(node:8904) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead
(node:8904) UnhandledPromiseRejectionWarning: Error: Unexpected error while acquiring application default credentials: Could not load
the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.
at GoogleAuth. (C:\Users\sandrpa\Downloads\nodejs-docs-samples-master\functions\ocr\app\node_modules@google-cloud\vision\node_modules\google-auth-library\build\src\auth\googleauth.js:248:31)

@stephenplusplus
Copy link
Contributor

https://cloud.google.com/docs/authentication/getting-started#auth-cloud-implicit-nodejs has some good information about getting started with authorization.

@sandrapavankumar
Copy link
Author

Thanks @stephenplusplus its working now.

@google-cloud-label-sync google-cloud-label-sync bot added the api: vision Issues related to the googleapis/nodejs-vision API. label Jan 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: vision Issues related to the googleapis/nodejs-vision API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants