语法错误:缺少)参数列表后,使用异步时 [英] SyntaxError: missing ) after argument list, When using async
问题描述
为什么我收到此错误当我使用 async
?
Why am I getting this error When I use async
?
我的代码:
bot.onText(/\/start/, async msg => {
const opts = {
parse_mode: 'Markdown' ,
reply_markup: JSON.stringify({
keyboard: StartKeyboard,
resize_keyboard: true,
one_time_keyboard: true
})
};
await bot.sendMessage(msg.chat.id, 'Hi', opts);
});
错误:
bot.onText(/\/start/, async msg => {
^^^^^
SyntaxError: missing ) after argument list
我正在使用带有依赖项的node.js v6.11.0:
I'm using node.js v6.11.0 with "dependencies":
{ "babel-polyfill": "^6.23.0",
"cheerio": "^1.0.0-rc.2",
"dotenv": "^4.0.0",
"firebase": "^4.1.2",
"firebase-admin": "^5.0.0",
"node-telegram-bot-api": "^0.27.1",
"request": "^2.81.0" },
推荐答案
您的NodeJS版本(6.11 LTS)太旧,不支持 async / await
功能。语法错误是Javascript解释器无法识别 async
令牌并对参数感到困惑的结果。
Your version of NodeJS (6.11 LTS) is too old and does not support the async/await
features. The syntax error is a result of the Javascript interpreter not recognizing the async
token and getting confused about arguments.
升级到NodeJS 7.6或更高版本。 https://www.infoq.com/news/2017/02 / node-76-async-await
Upgrade to NodeJS 7.6 or later. https://www.infoq.com/news/2017/02/node-76-async-await
在以前的版本中,执行异步行为的唯一方法是使用 promises 。
In prior versions, the only way to perform asynchronous behaviour is to use promises.
这篇关于语法错误:缺少)参数列表后,使用异步时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!