@babel/eslint-parser 在 vue 文件上抛出错误
@babel/eslint-parser throwing error on vue files
我已经在我的 webpack 和 vue 项目上使用 @babel/eslint-parser 和 eslint-plugin-vue 设置了 eslint-webpack-plugin,但是当我尝试检查 vue 文件时它抛出以下错误:
Error in phone-link.vue
1:0 error Parsing error: This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0)
我的设置在 none vue 文件上运行时是否遗漏了什么?
包:
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.16.0",
"eslint": "^8.2.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-vue": "^8.0.3",
"eslint-webpack-plugin": "^3.1.0",
Webpack 配置
const ESLintPlugin = require('eslint-webpack-plugin');
plugins: [
new ESLintPlugin({
extensions: ['vue', 'js'],
})
],
eslintrc
"extends": [
"eslint:recommended",
"airbnb-base",
"plugin:vue/recommended"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
示例 vue 文件
<template>
<a :href="phoneLinkNumber" class="">{{ phoneLinkText }}</a>
</template>
<script>
import SiteConstants from '../Constants/site-constants.js';
export default {
name: 'phone-link',
props: {
phoneLinkText: {
default: SiteConstants.PhoneNumber,
},
},
data() {
return {
phoneLinkNumber: `tel:${SiteConstants.PhoneNumber.replace(/\s/g, "")}`,
}
},
}
</script>
最后我为 vue-eslint-parser
更改了 babel 解析器:
"parser": "vue-eslint-parser",
我已经在我的 webpack 和 vue 项目上使用 @babel/eslint-parser 和 eslint-plugin-vue 设置了 eslint-webpack-plugin,但是当我尝试检查 vue 文件时它抛出以下错误:
Error in phone-link.vue
1:0 error Parsing error: This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0)
我的设置在 none vue 文件上运行时是否遗漏了什么?
包:
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.16.0",
"eslint": "^8.2.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-vue": "^8.0.3",
"eslint-webpack-plugin": "^3.1.0",
Webpack 配置
const ESLintPlugin = require('eslint-webpack-plugin');
plugins: [
new ESLintPlugin({
extensions: ['vue', 'js'],
})
],
eslintrc
"extends": [
"eslint:recommended",
"airbnb-base",
"plugin:vue/recommended"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
示例 vue 文件
<template>
<a :href="phoneLinkNumber" class="">{{ phoneLinkText }}</a>
</template>
<script>
import SiteConstants from '../Constants/site-constants.js';
export default {
name: 'phone-link',
props: {
phoneLinkText: {
default: SiteConstants.PhoneNumber,
},
},
data() {
return {
phoneLinkNumber: `tel:${SiteConstants.PhoneNumber.replace(/\s/g, "")}`,
}
},
}
</script>
最后我为 vue-eslint-parser
更改了 babel 解析器:
"parser": "vue-eslint-parser",