SyntaxError: none) after argument list when using async

Why do I get this error when I use async?

My code is:

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 am 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" },
+15
source share
2 answers

Your version of NodeJS (6.11 LTS) is deprecated and does not support features async/await. The syntax error is the result of the fact that the Javascript interpreter does not recognize the token asyncand is not confused in the arguments.

Upgrade to NodeJS 7.6 or later. https://www.infoq.com/news/2017/02/node-76-async-await

.

+16

/ node, babel. ES6 (node v6.9.1).

npm install --save babel-preset-es2015 babel-preset-stage-0

.babelrc :

{ "presets": ["es2015", "stage-0"] }

, babel-cli babel-node

sudo npm install -g babel-cli

babel-node app.js
+3

Source: https://habr.com/ru/post/1685976/


All Articles