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.

Error with async: "Parsing error: Unexpected token =>"

See original GitHub issue
  • ESLint Version: 3.16.0

  • Node Version: 6.9.1

  • npm Version: 3.10.8

  • parser: default

  • configuration

...
"extends": ["eslint:recommended"],
"parserOptions": {
    "sourceType": "module",
    "ecmaVersion": 7,
    "ecmaFeatures": {
        "jsx": true,
        "experimentalObjectRestSpread": true
    }
},
...

source code

!(async () => {
    try {
        const result = await Promise.resolve('Hello');
        console.log('>>>>>', result);
    } catch (error) {
        console.error('Error in demo', error);
    }
})();

eslint check result

error  Parsing error: Unexpected token =>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

83reactions
not-an-aardvarkcommented, Feb 22, 2017

Thanks for the report. Async functions are an ES2017 (or “ES8”) feature, but you have ecmaVersion: 7 in your config. To fix this, you should use ecmaVersion: 8 or ecmaVersion: 2017 in your config.

9reactions
not-an-aardvarkcommented, Sep 25, 2017

ecmaVersion should not be in ecmaFeatures.

{
    "env": {
        "browser": true,
        "node": true,
        "es6": true
    },
    "extends": ["eslint:recommended", "plugin:react/recommended"],
    "parserOptions": {
+       "ecmaVersion": 8,
        "ecmaFeatures": {
-           "ecmaVersion": 8,
            "experimentalObjectRestSpread": true,
            "jsx": true
        },
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "no-console": 0,
        "disallowMultipleVarDecl": 0,
        "maximumLineLength": 0,
        "indent": [
            "error",
            2
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ]
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint Parsing error: Unexpected token function with async
Just in case this is happening to people using async/await for the first time. This error also appears if you use await inside...
Read more >
error with await "Parsing error: Unexpected token" #319 - GitHub
I am using a async/await library (https://github.com/yortus/asyncawait) to call Promises as if they are running synchronously. here is ...
Read more >
Unexpected token error after adding await keyword to Node.js ...
Neil Lovelace : I placed the await in front of checkToken but thats what is giving me the 401 error. Once I remove...
Read more >
SyntaxError: Unexpected token - JavaScript - MDN Web Docs
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided.
Read more >
Parsing Error: Unexpected Token ; - ServiceNow Community
I am trying to create a business rule that requires a field in a child table/record to be mandatory when certain fields in...
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