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.

'Parsing error: Unexpected token function' using async/await + ecmaVersion 2017

See original GitHub issue

Tell us about your environment

  • ESLint Version: 3.18.0
  • Node Version: 7.7.3
  • npm Version: 4.1.2

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

Please show your full configuration:

  root: true,
  parserOptions: {
    ecmaVersion: 2017,
    sourceType: 'module'
  },
  extends: ['eslint:recommended', 'airbnb-base'],
  env: {
    'node': true
  },
  rules: {
    'import/no-unresolved': 'off',
    'import/no-extraneous-dependencies': 'off',
    'func-names': 'off',
    'no-multi-spaces': 'off',
    'spaced-comment': ["error", "always", { "markers": ["/"] }],
    'comma-dangle': ['error', 'always-multiline'],
    'padded-blocks': 'off',
    'linebreak-style': 'off',
    'class-methods-use-this': 'off',
    'indent': ['error', 2],
    'max-len': ['error', 120, 2, { ignoreComments: true }],
    'no-unused-vars': ['error', { vars: 'local', args: 'after-used' }],
    'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }],
    'no-nested-ternary': 'off',
    'no-underscore-dangle': ['error', {'allow': ['_super', '_lookupFactory']}],
    'object-shorthand': ['error', 'methods'],
  }

What did you do? Please include the actual source code causing the issue.

describe('Some Mocha Test', () => {
  let target, context, exampleGame;
  ...
  const checkAttributes = function (callback) {
    return async function () { // Error here
      return callback(await target.getAttributesAsync(exampleGame, context));
    };
  };
}

What did you expect to happen? eslint passes

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

error  Parsing error: Unexpected token function

A similar issue happens with =>, as noted here

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

181reactions
not-an-aardvarkcommented, Sep 3, 2017

To enable parsing for async functions, you should include this in your config:

{
    "parserOptions": {
        "ecmaVersion": 2017
    }
}
0reactions
yochaiakcommented, Dec 17, 2017

Many Many Many Thanks 👍 👍 👍 👍

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 >
eslint/eslint - Gitter
Has anyone reported an issue with .eslintrc.js globals not working in a subdirectory? ... .com/questions/36001552/eslint-parsing-error-unexpected-token.
Read more >
Js - Parsing Error For Async Function
Mar 30 2017 'Parsing error: Unexpected token function' using async/await #9761 ... This is the example code from my video about using async/await...
Read more >
Unexpected token error after adding await keyword to ...
Dylan Sather (Pipedream) : Hi , getting used to async / await and asynchronous programming in JS can take a long time even...
Read more >
How To Fix - "Parsing error: Unexpected Token" in React.js ...
This could be due to a typo mistake, missing something in the code etc. Also could be dev environment and ESLint parsing styles...
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 Reddit Thread

No results found

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