eslint: Arrow functions: "Parsing error: unexpected token ="

Tell us about your environment

  • ESLint Version: 4.19.1
  • Node Version: 7.9.0
  • npm Version: 5.5.1

What parser (default, Babel-ESLint, etc.) are you using? "babel-eslint": "^8.2.2",

Please show your full configuration:

Configuration
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-jest": "^21.15.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

anyFunc = (e) => {
    // does not matter what is inside
  }
./node_modules/.bin/eslint myfile.jsx

What did you expect to happen? Errors should be output and shown in VS Code.

What actually happened? Please include the actual, raw output from ESLint.

34:16 error  Parsing error: Unexpected token =

✖ 1 problem (1 error, 0 warnings)

VS Code integration breaks: the first = is underlined with this message:[eslint] Parsing error: unexpected token =. Linting is broken for entire file, no other errors are shown even though they exist, and autofix on save does not work.

Everything works as expected for files without arrow functions both via CL and in VSCode.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

You should add babel-eslint as parser.

extends: airbnb
parser: babel-eslint
plugins:
  - react
  - jest
(...)

babel-eslint is not needed for this from at least version 5.9.0 (probably earlier) I was able to use arrow functions by setting the ecmaVersion to 2018

{
  "parserOptions": {
    "ecmaVersion": 2018
  },

  "env": {
    "node": true,
    "es6": true
  },
  
  "extends": "eslint:recommended"
}

@euharrison Thanks! Adding babel-eslint solves the issue.

Yes - adding the parser worked. Thanks!

@ChampIsMe parser: babel-eslint at the top level in your eslint config should do the trick, see @euharrison’s earlier comment for an example

How to add babel-eslint was not indicated

@euharrison Thanks! Adding babel-eslint solves the issue.

@euharrison Thanks! Adding babel-eslint solves the issue.