Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: missing ) after argument list, When using async

Tags:

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" }, 
like image 423
Saeed Heidarizarei Avatar asked Sep 19 '17 17:09

Saeed Heidarizarei


People also ask

How do you fix a missing after the argument list?

The "SyntaxError: missing ) after argument list" occurs when we make a syntax error when calling a function, e.g. forget to separate its arguments with a comma. To solve the error make sure to correct any syntax errors in the arguments list of the function invocation.

What does uncaught SyntaxError missing after argument list mean?

The JavaScript exception "missing ) after argument list" occurs when there is an error with how a function is called. This might be a typo, a missing operator, or an unescaped string.


1 Answers

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.

like image 115
Soviut Avatar answered Sep 25 '22 22:09

Soviut