这是我引发异常的代码。无法弄清楚为什么它说“意外的保留字”。 main() 函数是异步类型。它并没有提示上面的代码行。
const { BlobServiceClient } = require("@azure/storage-blob");
async function main() {
try {
const blobServiceClient = await BlobServiceClient.fromConnectionString('some string');
let i = 1;
const result = await blobServiceClient.listContainers();
for await (const container of result) {
console.log(`Container ${i++}: ${container.name}`);
}
} catch (error) {
console.log(error);
}
}
main();
最佳答案
您收到此错误是因为您的 Node 版本低于 10.0 并且不支持 for await...of
.作为旁注,for await
在这里没有效果,可以只替换for
原来api确实需要它
添加:
来自 docs : 你可以使用 for await of
如果您的运行时支持它,或者以老式方式迭代一个可迭代对象
let containerItem = await result.next();
while (!containerItem.done) {
console.log(`Container ${i++}: ${containerItem.value.name}`);
containerItem = await iter.next();
}
关于javascript - for await 给出 SyntaxError : Unexpected reserved word inside a async function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59184155/