Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Parsing error: Unexpected token < ..." using VueCli3 and airbnb eslint

I know this may seem like a duplicate question, I still get this type of eslint errors after trying the following:

  • https://github.com/prettier/prettier/issues/3720 (i already installed eslint-plugin-vue)

  • Vue.js eslint Parsing error .: unexpected token (not really related to my question, but I tried it anyway)

  • https://github.com/vuejs/eslint-plugin-vue/issues/186

  • "Unexpected token <" for VueJS running with Webpack

Here is part of my package.json setting:

"devDependencies": {
    "@vue/cli-plugin-babel": "^3.0.5",
    "@vue/cli-plugin-eslint": "^3.0.5",
    "@vue/cli-plugin-unit-jest": "^3.0.5",
    "@vue/cli-service": "^3.0.5",
    "@vue/eslint-config-airbnb": "^4.0.0",
    "@vue/test-utils": "^1.0.0-beta.20",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "^10.0.1",
    "babel-jest": "^23.6.0",
    "eslint": "^5.8.0",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-vue": "^5.0.0-0",
    "vue-template-compiler": "^2.5.17"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "@vue/airbnb"
    ],
    "rules": {},
    "parserOptions": {
      "parser": "babel-eslint",
      "ecmaVersion": 6
    }
  },

Here is my .eslintrc.js file:

module.exports = {
  parserOptions: {
    sourceType: 'module',
    allowImportExportEverywhere: true,
  },
  rules: {
    'no-console': 0,
  },
  plugins: ['vue'],
};

Here is a detailed version of eslint error:

error: Parsing error: Unexpected token < at src/App.vue:1:1:
> 1 | <template>
    | ^
  2 |   <div id="app">
  3 |     <router-view/>
  4 |   </div>

Here is my App.vue source code:

<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'BuilderApp',
  data() {
    return {
      dragEvents: ['drag', 'dragstart', 'dragend', 'dragover', 'dragenter', 'dragleave', 'drop'],
    };
  },
  mounted() {
    // prevent default action for all defined dragEvents
    if (this.dragAndDropCapable()) {
      this.dragEvents.forEach((dragEvent) => {
        document.getElementById('app').addEventListener(dragEvent, (e) => {
          e.preventDefault();
          e.stopPropagation();
        }, false);
      });
    }
  },
  methods: {
    dragAndDropCapable() {
      const testDiv = document.createElement('div');
      return (('draggable' in testDiv)
          || ('ondragstart' in testDiv && 'ondrop' in testDiv))
          && 'FormData' in window
          && 'FileReader' in window;
    },
  },
};
</script>

<style>
.filter-disable .filter-count {
  background: #dadada;
}
</style>

I'm not sure what I am missing.

like image 702
Leesa Avatar asked Dec 03 '18 20:12

Leesa


1 Answers

You miss the "parser" in your .eslintrc file.

Here is my .eslintrc

{
  "parser": "vue-eslint-parser",
  "parserOptions": {
    "ecmaVersion": 7,
    "sourceType": "module"
  }
}

vue-eslint-parser doc

like image 64
yulimchen Avatar answered Jan 03 '23 00:01

yulimchen