我使用的是VueJS网页包模板:https://github.com/vuejs-templates/webpack

Example Route:

const AuthRoute = () => import(/* webpackChunkName: "authroute" */ './AuthRoute.vue')

Example Error:

[eslint]分析错误:意外的令牌导入

我遵循了Webpack的动态导入部分提供的步骤,以及Anthony Gore关于如何在路由级别使用VueJS完成代码拆分的博客文章.更具体地说,以下是我的设置:

Package.json

...
"babel-core": "^6.22.1",
"babel-eslint": "^8.0.3",
"babel-jest": "^21.2.0",
"babel-loader": "^7.1.1",
"babel-plugin-dynamic-import-webpack": "^1.0.2",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.24.1",
"eslint": "^4.13.1"
...

.babelrc

{
  "presets": [
    ["env", {
      "modules": false
    }],
    "stage-2"
  ],
  "plugins": [
    "dynamic-import-webpack",
    "syntax-dynamic-import",
    "transform-runtime"
  ],
  "env": {
    "test": {
      "presets": ["env", "stage-2"]    }
  }
}

.eslintrc.js

parserOptions: {
  parser: 'babel-eslint',
  sourceType: 'module',
  allowImportExportEverywhere: true
}

我有点不明白为什么我仍然看到这个错误.当使用npm run devnpm run build时,我的代码按预期运行和工作,但是这个解析错误阻止了文件的其余部分被删除,我无法 suppress 它.

感谢您的帮助!

推荐答案

.eslintrc.js

parserOptions: {
  parser: 'babel-eslint',
  sourceType: 'module',
  allowImportExportEverywhere: true
}

Should Be:

parser: 'babel-eslint',
parserOptions: {
  sourceType: 'module',
  allowImportExportEverywhere: true
}

资料来源:https://eslint.org/docs/user-guide/configuring#specifying-parser

With (@vue/cli)

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

Vue.js相关问答推荐

如何配置nuxt 3,以便当我直接打开用nPM run generate生成的静态页面时,它可以正常工作?

VITE:无法为VUE单文件组件加载URL

Vuejs - 更新数组中对象的数组

如何在 vue 组件之外访问$apollo?

Vue:需要禁用页面上的所有输入

eslint – 如何知道 defined定义规则的位置

Javascript/vue.js 接收json

VueJS 通过渲染传递数据

Vue CLI - 将构建输出组合到单个 html 文件

样式化 Vue 插槽

如何从 vue 组件调用 App.vue 中的方法

Vue CLI 3 sass-resources-loader - Options.loaders 未定义

Vue3在按钮单击时以编程方式创建组件实例

如何在 JEST 测试中模拟全局 Vue.js 变量

Vue.js 的 $emit 和 $dispatch 有什么区别?

使用 Vue 的点击编辑文本字段

Vue 2.0 设置路由 - 不要使用new来产生副作用

为什么 router.currentRoute.path 没有react?

用于身份验证标头的 vue-resource 拦截器

Vuetify v-data-table 固定标题不起作用