gpt4 book ai didi

javascript - 如何修复语法错误: await is only valid in async function in Google cloud vision

转载 作者:行者123 更新时间:2023-12-02 23:27:03 24 4
gpt4 key购买 nike

我想使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com