Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected token "=" reported while running eslint on arrow functions

I have a JavaScript class and inside it I have an async method which looks like below.

class ABC {
    func = async () => { //----line 10
        //some code
    }
    func2 = () => { //----line 11
        //some code 
    }
}

When I run ESLint it's reporting one error. The application itself is working as expected.

unexpected token '=' at line 10 (& 11)

eslintrc.json

{
   "env":{
       "es2021":true
    }
}

What do I need to do in order to get rid of these lint errors and still keep these methods as arrow functions?

ESLint version: eslint :"^7.32.0"

like image 277
Naxi Avatar asked Oct 15 '25 15:10

Naxi


1 Answers

Upgrade to ESLint 8 and add this setting to your .eslintrc:

"parserOptions": {
  "ecmaVersion": 2022
}

Reason: you are using class fields. Support for class fields syntax in ESLint has been introduced with version 8.

Note that the specification of class fields, although already finalized in April 2021, will be published with ECMAScript 2022, expected next year.

like image 194
GOTO 0 Avatar answered Oct 17 '25 06:10

GOTO 0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!