1

I'd like to use Google cloud vision API. I copied the code but I'm getting the following error : SyntaxError: await is only valid in async function.

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

// Creates a client
const client = new vision.ImageAnnotatorClient();

/**
 * TODO(developer): Uncomment the following line before running the sample.
 */
const fileName = '/Tickets/leclerc.jpg';

// Performs text detection on the local file
const [result] = await client.textDetection(fileName);
const detections = result.textAnnotations;
console.log('Text:');
detections.forEach(text => console.log(text));    

Any ideas on how to solve it ?

Thanks a lot

GreensterRox
  • 6,432
  • 2
  • 27
  • 30
Yacasuone
  • 69
  • 5

1 Answers1

1

An await method needs to be enclosed into an async function, this is pretty easy to fix.

const detectLocalFile = async function() {
  const [result] = await client.textDetection(fileName);
  {...}
}
Jalu
  • 332
  • 3
  • 13