7

I created a Laravel project and installed VSCode and all those necessary extensions. One of these is ESLint and it's working fine with JS file, but when I open a Vue component like (resources/js/component/ExampleComponent.vue), I get this error from ESLint:

"Parsing error: Unexpected token < eslint [1, 1]"

My .eslintrc.jsfile was generated using ./node_modules/.bin/eslint --init and answering the questions.

I already googled and found this solution:

npm install babel-eslint --save-dev

and add this to .eslintrc.js:

parser: "babel-eslint"

but it doesn't work anyway, the error stay there.

Here is my ExampleComponent.vue (unmodified from Laravel):

<template> (ESLint error here: "Parsing error: Unexpected token < eslint [1,1]")
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">
                        Example Component
                    </div>

                    <div class="card-body">
                        I'm an example component.
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

Here is my .eslintrc.js:

module.exports = {
  env: {
    browser: true,
    es6: true,
  },
  extends: 'airbnb-base',
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly',
  },
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module',
    parser: "babel-eslint",
  },
  plugins: [
    'vue',
  ],
  rules: {
  },
};
2
  • Seems like you didn't install the Vue plugin Commented Apr 21, 2019 at 21:03
  • Are you saying about eslint-plugin-vue? When I used eslint --init, it installed the vue plugin for me. I have this in my package.json file (related to ESLint): "babel-eslint": "^10.0.1", "eslint": "^5.16.0", "eslint-config-airbnb-base": "^13.1.0", "eslint-config-google": "^0.12.0", "eslint-plugin-babel": "^5.3.0", "eslint-plugin-import": "^2.17.2", "eslint-plugin-vue": "^5.2.2", Commented Apr 21, 2019 at 21:11

1 Answer 1

7

I believe you need the plugin eslint-plugin-vue, and to set your .eslintrc.js configuration to one of the bundle configurations:

  • "extends": ["plugin:vue/base"]
  • "extends": ["plugin:vue/essential"]
  • "extends": ["plugin:vue/strongly-recommended"]
  • "extends": ["plugin:vue/recommended"]

You can read more about eslint-plugin-vue here - here is a reference for a similar issue you are having.

Hope this helps!

EDIT: this is an eslint config from a vue cli project:

module.exports = {
  "root": true,
  "env": {
    "node": true
  },
  "extends": [
    "plugin:vue/essential",
    "eslint:recommended"
  ],
  "rules": {},
  "parserOptions": {
    "parser": "babel-eslint"
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

As I'm using Airbnb base, I just put "plugin:vue/recommended" and "eslint:recommended" on my .eslintrc.js and now it's working. Thank you.
Using a .eslintc file in my root with the above as JSON fixed my issue.

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.