Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eslint throws parsing error unexpected token on named export

I have an index.js file which has the following named export in it.

export Main from './Main/Main'

However, eslint doesn't like this and throws the error

Parsing error: Unexpected token Main

I'm not sure why as the app is working properly and I believe that's valid syntax.

My .eslintrc file looks like this

{
  env: {
    es6: true,
    browser: true
  },
  parserOptions: {
    ecmaVersion: 6,
    sourceType: "module",
    ecmaFeatures: {
      jsx: true,
      experimentalObjectRestSpread: true
    }
  },
  plugins: [
    "react",
  ],
  extends: ["eslint:recommended", "plugin:react/recommended", "standard"],
  "rules": {
    "comma-dangle" : [2, "always-multiline"],
    "semi": [2, "never"],
    "no-extra-semi": 2,
    "jsx-quotes": [2, "prefer-single"],
    "react/jsx-boolean-value": [2, "always"],
    "react/jsx-closing-bracket-location": [2, {selfClosing: "after-props", nonEmpty: "after-props"}],
    "react/jsx-curly-spacing": [2, "never", {"allowMultiline": false}],
    "react/jsx-max-props-per-line": [2, {maximum: 3}],
    "react/jsx-no-literals": 2,
    "react/sort-prop-types": 2,
    "react/self-closing-comp": 2,
    "react/sort-comp": 2
  },
}
like image 364
Tyler McGinnis Avatar asked Mar 25 '16 21:03

Tyler McGinnis


1 Answers

Figured it out. It's an experimental feature so I need to enable babel-eslint as my eslint parser.

Now my .eslintrc looks like this

{
  parser: "babel-eslint",
  env: {
    es6: true,
    browser: true
  },
  parserOptions: {
    ecmaVersion: 6,
    sourceType: "module",
    ecmaFeatures: {
      jsx: true,
      experimentalObjectRestSpread: true
    }
  },
  plugins: [
    "react",
  ],
  extends: ["eslint:recommended", "plugin:react/recommended", "standard"],
  "rules": {
    "comma-dangle" : [2, "always-multiline"],
    "semi": [2, "never"],
    "no-extra-semi": 2,
    "jsx-quotes": [2, "prefer-single"],
    "react/jsx-boolean-value": [2, "always"],
    "react/jsx-closing-bracket-location": [2, {selfClosing: "after-props", nonEmpty: "after-props"}],
    "react/jsx-curly-spacing": [2, "never", {"allowMultiline": false}],
    "react/jsx-max-props-per-line": [2, {maximum: 3}],
    "react/jsx-no-literals": 2,
    "react/sort-prop-types": 2,
    "react/self-closing-comp": 2,
    "react/sort-comp": 2
  },
}
like image 145
Tyler McGinnis Avatar answered Sep 27 '22 20:09

Tyler McGinnis