SyntaxError: missing ) 在参数列表之后,使用异步时 [英] SyntaxError: missing ) after argument list, When using async

查看:34
本文介绍了SyntaxError: missing ) 在参数列表之后,使用异步时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我在使用 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

在以前的版本中,执行异步行为的唯一方法是使用 承诺.

In prior versions, the only way to perform asynchronous behaviour is to use promises.

这篇关于SyntaxError: missing ) 在参数列表之后,使用异步时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆