16

Why is eslint throwing this error? The Javascript runs without issue inside of React Native. The code was taken from the react-navigation example at : https://reactnavigation.org/docs/intro/

Javascript:

static navigationOptions = { header: null };

eslint error:

error  Parsing error: Unexpected token =

.eslintrc.js file:

module.exports = {
    "extends": "standard",
    "plugins": [
      "react",
      "react-native"
    ]
};
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Jeremy
  • 555
  • 2
  • 4
  • 10

2 Answers2

36

The syntax is not yet standardised, but a stage-2 proposal for inclusion in Javascript (see "Class Fields" on https://github.com/tc39/proposals).

Try adding the following option above "extends" in your .eslintrc.js:

"parser": "babel-eslint",
benwixen
  • 972
  • 9
  • 15
  • [babel-eslint](https://www.npmjs.com/package/babel-eslint) is now deprecated - use [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser) instead. – Shl Sep 12 '21 at 20:34
1

Sometimes I get this error out of blue for the code that worked previously, so I know it's not a syntax error. Restarting VSCode solves my issue.

Mario Nezmah
  • 497
  • 2
  • 6
  • 19