我想使用 Google 云视觉 API。我复制了代码,但收到以下错误: SyntaxError:await 仅在异步函数中有效。
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));
有什么解决办法吗?
非常感谢
最佳答案
await 方法需要包含在异步函数中,这很容易修复。
const detectLocalFile = async function() {
const [result] = await client.textDetection(fileName);
{...}
}
关于javascript - 如何修复语法错误: await is only valid in async function in Google cloud vision,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56688180/