javascript - 仅当 'module' 选项设置为 'esnext' 时才允许使用顶级 'await' 表达式
问题描述
我正在执行 Stripes 集成步骤,并在步骤 2.1 中发现我的代码错误(https://stripe.com/docs/connect/collect-then-transfer-guide#create-an-account-link)
如何修复此错误?
代码:
const stripe = require('stripe')('someID');
const account = await stripe.accounts.create({
type: 'express',
});
错误:
仅当 'module' 选项设置为 'esnext' 或 'system' 并且 'target' 选项设置为 'es2017' 或更高版本时才允许使用顶级 'await' 表达式。ts(1378)
解决方案
您可以将 const 帐户的代码包装在异步函数中,因为您的目标选项不支持顶级等待。
const account = async () => {
await stripe.accounts.create({
type: "express",
});
};
这取决于您的代码是要返回某些内容还是要在等待之后执行一些其他任务。
如果您想使用顶级等待,有关使用顶级等待的更多信息请参见https://stackoverflow.com/a/56590390/9423152
推荐阅读
- python - 如何在python中对角循环遍历二维列表?
- java - 将只有“行”和“列”的 JSON 响应解析为 POJO
- python - 从 Python 中的嵌套 for 循环中绘制子图
- javascript - Webpack 和 svg-inline-loader 不起作用
- git - Git pull vs fetch - 新获取的分支没有区别?
- javascript - 意外的标记 '。' 尽管我有 95% 的把握,但我想我会放一个“。”。这里
- mysql - 使用 MySQL 限定值时我犯了错误吗?我已经运行了同一个查询的多个版本,但每个版本都不会输出任何内容
- r - 如何绘制彼此相邻的图表?
- css - 重叠的网格元素:第二个 div 无法加载
- c# - 如何确保 C# 应用程序从睡眠中醒来后会响应(Windows 10)?