Parsing error: Unexpected token < at ... Vue CLI3

在使用vue cli3的时候,遇到如下问题:

error: Parsing error: Unexpected token < at srcviewsindex.vue:1:1:
> 1 | <template>
    | ^
  2 |   <div class="index">
  3 |     <router-view></router-view>
  4 |     <TabBar :data="tabbarData"></TabBar>

查阅了许多网站,都不能解决此问题,最后,在 

https://stackoverflow.com/questions/53601579/parsing-error-unexpected-token-using-vuecli3-and-airbnb-eslint?r=SearchResults

找到了办法

打开你的   .eslintrc.js 文件,找到 parser

这是我的  .eslintrc.js 

module.exports = {
    rules: {
        'no-console': 'off',
        "parser": "vue-eslint-parser"
    },
}

注意:

  当我写入 import 时,就会报上述错误,这个时候,只需要把 .eslintrc.js 里的 

"parser": "vue-eslint-parser" 注释掉,重新启动项目。然后,取消掉注释,再次重启项目,就没有报错了。

为什么会这样,我也不理解。如果你们有了更好的解决办法,麻烦给我留言,谢谢!!!
原文地址:https://www.cnblogs.com/yanglang/p/13615586.html