eslint: Async Arrow Function "Unexpected token ="

Tell us about your environment

  • ESLint Version: 4.18.1
  • Node Version: 8.9.1
  • npm Version: 5.5.1

What parser (default, Babel-ESLint, etc.) are you using? Babel-ESlint

Please show your full configuration:

Configuration
{
  "extends": "airbnb",
  "parserOptions": {
    "ecmaVersion": 8
  },
  "env": {
    "jest": true,
    "browser": true
  },
  "rules": {
    "semi": [
      2,
      "never"
    ],
    "no-unexpected-multiline": 2,
    "import/no-named-as-default": 0,
    "import/no-named-as-default-member": 0,
    "react/prop-types": 0,
    "react/jsx-filename-extension": [
      1,
      {
        "extensions": [
          ".js",
          ".jsx"
        ]
      }
    ],
    "jsx-a11y/anchor-is-valid": [
      "error",
      {
        "components": [
          "Link"
        ],
        "specialLink": [
          "to"
        ]
      }
    ],
    "no-unused-expressions": [
      "error",
      {
        "allowTernary": true
      }
    ]
  }
}

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

  callApi = async (url) => {
    const response = await fetch(url)
    const body = await response.json()

    if (response.status !== 200) {
      throw Error(body.message)
    }

    return body
  }
eslint src

What did you expect to happen? ESLint done.

What actually happened? Please include the actual, raw output from ESLint. " error Parsing error: Unexpected token = " [ callApi = async (url) … is the problem ]

About this issue

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

Most upvoted comments

@codeblooded I think your error is unrelated. In the parserOptions section, you have:

  "parserOptions": {
    "ecmaVersion": 6,
    "ecmaFeatures": {
      "globalReturn": true,
      "ecmaVersion": 8,
      "experimentalObjectRestSpread": true
    }
  },

This should just be:

  "parserOptions": {
    "ecmaVersion": 8,
    "ecmaFeatures": {
      "globalReturn": true,
      "experimentalObjectRestSpread": true
    }
  },

ecmaVersion generally isn’t supposed to go in the ecmaFeatures object.

@platinumazure.

specifying the node version in the engines field of my package.json fixed the problem. Thanks!