Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

javascript - SyntaxError: missing ) after argument list, When using async

Why am I getting this error When I use async?

My Code:

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);
});

Error:

bot.onText(//start/, async  msg => {
                      ^^^^^
SyntaxError: missing ) after argument list

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" },
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...