New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
huarse opened this Issue Feb 22, 2017 · 10 comments

Comments

Projects
None yet
8 participants
@huarse
Copy link

huarse commented Feb 22, 2017

  • 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 =>

@eslintbot eslintbot added the triage label Feb 22, 2017

@not-an-aardvark

This comment has been minimized.

Copy link
Member

not-an-aardvark commented 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.

@not-an-aardvark not-an-aardvark added question and removed triage labels Feb 22, 2017

@huarse

This comment has been minimized.

Copy link

huarse commented Feb 22, 2017

THX @not-an-aardvark, it works. I always thought that 'async' is ES7 features

@anwarhamr

This comment has been minimized.

Copy link

anwarhamr commented Sep 25, 2017

I'm still having this issue in Atom. I've tried both values ecmaVersion: 8 and ecmaVersion: 2017 in my config. I'm using Atom editor w/ the linter packages: linter 2.2.0, linter-eslint 8.3.2, linter-ui-default 1.6.10.
Here is the code failing:

export default class myclass{
  async handleDiscoverPeripheral(peripheral) { ...}
}

my .eslintrc.json:

{
    "env": {
        "browser": true,
        "node": true,
        "es6": true
    },
    "extends": ["eslint:recommended", "plugin:react/recommended"],
    "parserOptions": {
        "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"
        ]
    }
}
@not-an-aardvark

This comment has been minimized.

Copy link
Member

not-an-aardvark commented 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"
        ]
    }
}
@henryzp

This comment has been minimized.

Copy link

henryzp commented Oct 27, 2017

@huarse ,when i use ecmaVersion: 8

image

@not-an-aardvark , can you help me ?

my eslintrc:

{
    "extends": ["eslint:recommended"],
    "env": { 
        "es6": true,
        "node": true 
    },
    "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": 8,
        "ecmaFeatures": {
            "jsx": true,
            "experimentalObjectRestSpread": true
        }
    }
}
@aladdin-add

This comment has been minimized.

Copy link
Member

aladdin-add commented Oct 27, 2017

@henryzp it might be you are using a very earlier version ESLint (does not support ES8), upgrade to latest should work~

@henryzp

This comment has been minimized.

Copy link

henryzp commented Oct 27, 2017

@Aladdin-ADD

I use vscode:

image

I guess its version is not the latest。。。

@aladdin-add

This comment has been minimized.

Copy link
Member

aladdin-add commented Oct 27, 2017

well, you can upgrade and try. if still got some problems, please feel free to leave a comment.

just a friendly reminder: it seems to be vscode-eslint version, not eslint. you can use eslint -v(global installed) or ./node_modules/.bin/eslint -v(local-installed) to see eslint verson.

@kstiopin

This comment has been minimized.

Copy link

kstiopin commented Nov 28, 2017

Have the same issue and have tried all possible solutions mentioned here and in similar topics.
So this is the error:

Syntax error: C:/projects/project1/src/containers/OfferOverview.js: Unexpected token (84:40)
  83 |
> 84 |   initialGetProduct = async (productId) => {
     |                                         ^
  85 |     await dispatch(resetOfferStateAction());
  86 |     dispatch(getProductAction(productId));
  87 |     this.selectProduct(productId);

This is the Component:

export class OfferOverview extends Component {
  componentWillMount() {
    const { location } = this.props;
    const productId = location.query && location.query.product_id;
    if (productId) {
      this.initialGetProduct(productId);
    }
  }

  initialGetProduct = async (productId) => {
    await dispatch(resetOfferStateAction());
    dispatch(getProductAction(productId));
    this.selectProduct(productId);
  }

  render() { ... }
}

this is my .babelrc file:

{
  "presets": [
    "es2017",
    "react",
    "stage-0"
  ],
  "plugins": [
    "react-hot-loader/babel",
    ["import", { "libraryName": "antd", "style": "css" }]
  ]
}

eslint:

module.exports = {
  root: true,

  parser: 'babel-eslint',

  // import plugin is termporarily disabled, scroll below to see why
  plugins: [/*'import', */'flowtype', 'jsx-a11y', 'react'],

  env: {
    browser: true,
    commonjs: true,
    node: true
  },

  parserOptions: {
    ecmaVersion: 2017,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
      generators: true,
      experimentalObjectRestSpread: true
    }
  },

  settings: {
    'import/ignore': [
      'node_modules',
      '\\.(json|css|jpg|png|gif|eot|svg|ttf|woff|woff2|mp4|webm)$',
    ],
    'import/extensions': ['.js'],
    'import/resolver': {
      node: {
        extensions: ['.js', '.json']
      }
    }
  },

  rules: { ... }
};

and package.json dependencies:

"devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.13.2",
    "babel-eslint": "^6.1.2",
    "babel-plugin-transform-runtime": "^6.12.0",
    "babel-polyfill": "^6.26.0",
    "babel-preset-es2015": "^6.13.2",
    "babel-preset-es2016": "^6.24.1",
    "babel-preset-es2017": "^6.24.1",
    "babel-preset-react": "^6.11.1",
    "babel-preset-stage-2": "^6.13.0",
    "coveralls": "^2.11.12",
    "eslint": "^3.2.2",
    "eslint-config-airbnb": "^10.0.0",
    "eslint-plugin-react": "^6.0.0",
    "ignore-styles": "^4.0.0",
    "istanbul": "^1.0.0-alpha.2",
    "mocha": "^3.0.2",
    "nock": "^8.0.0",
    "react-addons-test-utils": "^15.3.0",
    "react-scripts": "0.2.1",
    "redux-mock-store": "^1.1.2",
    "redux-saga-devtools": "^0.1.2"
  },
  "dependencies": {
    "antd": "^2.12.3",
    "babel-polyfill": "^6.26.0",
    "enzyme": "^2.4.1",
    "eslint-plugin-flowtype": "^2.39.1",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "expect": "latest",
    "isomorphic-fetch": "^2.2.1",
    "jsdom": "^9.9.1",
    "lodash": "^4.17.4",
    "nuka-carousel": "^2.3.0",
    "pushstate-server": "latest",
    "react": "^15.2.1",
    "react-dom": "^15.2.1",
    "react-redux": "^4.4.5",
    "react-router": "^2.6.0",
    "react-router-redux": "^4.0.8",
    "react-sidebar": "^2.3.2",
    "redux": "^3.6.0",
    "redux-logger": "3.0.1",
    "redux-saga": "^0.14.3"
  },

Would appreciate any hint what can be wrong?

@platinumazure

This comment has been minimized.

Copy link
Member

platinumazure commented Nov 28, 2017

@kstiopin This seems to be a babel-eslint issue. Could you please open an issue there? Thanks!

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.