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
  • 572,313
  • 128
  • 898
  • 1,281
Jeremy
  • 535
  • 2
  • 4
  • 10

2 Answers2

35

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
  • 962
  • 9
  • 14
  • [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
  • 400
  • 1
  • 5
  • 17