5

I have this function:

import React from 'react';
import FilterList from './Filter/FilterList';

export default function Sidebar() {
  return (
    <div>
      <FilterList />
    </div>
  );
}

And included these packages:

  "dependencies": {
"bootstrap": "^3.3.7",
"font-awesome": "^4.7.0",
"i18n-react": "^0.4.0",
"react": "^15.6.1",
"react-bootstrap": "^0.31.2",
"react-dom": "^15.6.1",
"react-fontawesome": "^1.6.1",
"react-router-dom": "^4.1.2",
"rxjs": "^5.4.3",
"superagent": "^3.5.2",
"webpack": "^3.5.4"},

"devDependencies": {
"eslint": "^4.4.1",
"eslint-config-airbnb-base": "^11.3.1",
"eslint-plugin-import": "^2.7.0",
"nwb": "0.18.x",
"nwb-less": "^0.6.0",
"yaml-loader": "^0.5.0"},

But when running lint I get this error: error Parsing error: Unexpected token <

my .eslintrc file:

module.exports = {
"extends": "airbnb-base",
"plugins": [
  "import"
]};

What am I doing wrong?

5
  • please add more information about your presets-plugins, can you share your .babelrc? are you using eslint-babel? Commented Aug 17, 2017 at 6:11
  • Q is updated with my eslint file. Commented Aug 17, 2017 at 6:20
  • this seems to be more like an error that would arise from your .babelrc or webpack configuration then ESlint Commented Aug 17, 2017 at 6:22
  • could be. I didn't really setup webpack. If I remove the webpack package I get the same error. I guess webpack is used by nwb. Commented Aug 17, 2017 at 6:28
  • this link should help you: eslint-plugin-react issue #447 Commented Aug 17, 2017 at 7:55

3 Answers 3

5

You are getting this error because eslint don't know how to handle JSX syntax, and you need eslint-plugin-react for this.

But you are also missing other plugins required for airbnb-eslint-config to work. Do what they say in docs which is:

npm info "eslint-config-airbnb@latest" peerDependencies

and install printed dependencies (as dev dependencies).

As of today I get this list:

{ eslint: '^3.19.0 || ^4.3.0',
  'eslint-plugin-jsx-a11y': '^5.1.1',
  'eslint-plugin-import': '^2.7.0',
  'eslint-plugin-react': '^7.1.0' }
Sign up to request clarification or add additional context in comments.

2 Comments

Does this answer also apply if one is using Vue instead of React?
@JayBienvenu for Vue you are going to probably use this: eslint.vuejs.org
1

If you are using nmp5+, one shortcut would be:

npx install-peerdeps --dev eslint-config-airbnb

The -peerdeps refers to all the dependences.

Comments

1

If every peer dependency is added and you still get this error, be sure to check that your eslint config has the following options:

"parserOptions": {
    "ecmaFeatures": {
        "jsx": true,
        "modules": true
    }
}

1 Comment

Thanks, it worked. Didn't expect it to since I have .js file instead of .jsx.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.