Mike Williamson
Mike Williamson

Reputation: 3168

Don't understand ESLint arrow error

I do not understand the error that I am seeing, nor what I should change in my ESLint configurations to fix it, after digging around for a while.


I have a snippet of JS code using ECMA Version 6 (ES6) as follows:

const launchApp = async () => {
  await sequelize.sync()
  app.listen(config.port)
  console.log(`Server started on port ${config.port}.`)    
}

At the => above is an eslint error that says:

[eslint] Parsing error: Unexpected token => (22, 28)

I do not understand why this is considered an unexpected token. Other ES6 styling is working OK. I am setting the config within the package.json file, and the ESLint related part looks like this:

  "eslintConfig": {
    "parserOptions": {
      "ecmaVersion": 6
    },
    "env": {
      "node": true,
      "es6": true
    },
    "rules": {
      "semi": ["error", "always"]
    }
  }

What have I done wrong? What further configurations must I add? I looked at arrow-parens and arrow-body-style. As far as I can tell, they are both telling me that the es6 flag should be sufficient to allow for the arrow function style.

Upvotes: 2

Views: 407

Answers (1)

kingdaro
kingdaro

Reputation: 11998

Arrow functions are es2015, but async arrow functions are es2017. Set your "ecmaVersion" to 2017 (or higher) and it should work. See this finished proposals chart for when each ES feature post 2015 was added.

Upvotes: 6

Related Questions