question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async Arrow Function "Unexpected token ="

See original GitHub issue

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 ]

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
not-an-aardvarkcommented, Mar 29, 2018

@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.

1reaction
sethisidorecommented, Aug 30, 2018

@platinumazure.

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint parsing error when using arrow syntax with async
async / await is an ECMAScript 2017 feature, so if you change ecmaVersion: 8 instead of 6, this should work!
Read more >
Arrow function expressions - JavaScript - MDN Web Docs
Arrow functions can be async by prefixing the expression with the ... const func = (a, b, c) => 1; // SyntaxError: Unexpected...
Read more >
[Solved]-Syntax error on async arrow function-node.js
[Solved]-Syntax error on async arrow function-node.js ... The function syntax seems correct. ... How to fix 'Unexpected Token' error with async function ...
Read more >
async arrow function expected a return value - You.com
Async arrow function expected no return value ... token') // <-- unexpected we should throw } const session = await Iron.unseal(token, TOKEN_SECRET, ...
Read more >
Arrow Functions in JavaScript: Fat & Concise Syntax - SitePoint
Learn how to use JavaScript arrow functions, understand fat and concise ... Uncaught SyntaxError: unexpected token: ':' const seriesList ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found