What is causing Error: .eslintrc.js: Environment key "vue/setup-compiler-macros" is unknown
What is causing Error: .eslintrc.js: Environment key "vue/setup-compiler-macros" is unknown
我正在使用 Vue 3 和 Typescript 开发示例应用程序。
具体来说,我在 Vue SFC 部分使用新的 Vue v3.2 设置选项。 Vue 文档建议我添加
“vue/setup-compiler-macros”到正在工作的 eslintrc.js 文件的 env secyion。但是我现在收到一个错误
Syntax Error: Error: .eslintrc.js:
Environment key "vue/setup-compiler-macros" is unknown
at Array.forEach (<anonymous>)
有一段时间,如果我重新启动 VS Code,这似乎会消失(我承认这不是一个很好的解决方法),但现在即使这样也不起作用。当我保存文件并编译项目时发生错误。
我似乎在使用 VS 代码扩展 - ESLint v2.2.2。
eslintrc.js:
module.exports = {
root: true,
env: {
'vue/setup-compiler-macros': true,
node: true,
},
extends: [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/typescript/recommended',
],
parserOptions: {
ecmaVersion: 2020,
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
},
}
如有任何想法,我们将不胜感激。
我有同样的问题,已通过配置解决
globals: {
defineProps: "readonly",
defineEmits: "readonly"
}
offical guide来了,不知道'vue/setup-compiler-macros': true,
为什么不行
你可以查看,它帮助我正确解决了这个问题。
你基本上需要:
- 在您的终端上通过 运行
npm uni -D babel-eslint
删除 babel-eslint
。
- 通过 运行
npm i -D @babel/eslint-parser
在您的终端上安装 @babel/eslint-parser
。
- 使用以下内容更新 ESLint 配置中的
env
行(可以在 .eslintrc.js
、.eslintrc.json
或 package.json
中):
env: {
node: true,
'vue/setup-compiler-macros': true,
},
- 使用以下内容更新 ESLint 配置中的
parserOptions
行:
parserOptions: {
parser: '@babel/eslint-parser',
ecmaVersion: 2018,
requireConfigFile: false, // This will prevent Babel from looking for a config file you possibly don’t have or need.
},
- 如果
parserOptions
外面有 parser
行,您可以将其删除以避免冲突。
您需要将eslint-plugin-vue 升级到版本8,它根据发行说明添加了它。
硒也 https://github.com/vuejs/eslint-plugin-vue/pull/1685
使用配置创建 eslintrc.is 文件对我不起作用。
我在没有 运行 任何升级的情况下修复了这个错误,我所做的只是在 package.json 文件的 eslintConfig 部分添加“vue/setup-compiler-macros: true”
即:
"eslintConfig": {
...
"env": {
node: true,
"vue/setup-compiler-macros": true
}
}
我正在使用 Vue 3 和 Typescript 开发示例应用程序。 具体来说,我在 Vue SFC 部分使用新的 Vue v3.2 设置选项。 Vue 文档建议我添加 “vue/setup-compiler-macros”到正在工作的 eslintrc.js 文件的 env secyion。但是我现在收到一个错误
Syntax Error: Error: .eslintrc.js:
Environment key "vue/setup-compiler-macros" is unknown
at Array.forEach (<anonymous>)
有一段时间,如果我重新启动 VS Code,这似乎会消失(我承认这不是一个很好的解决方法),但现在即使这样也不起作用。当我保存文件并编译项目时发生错误。 我似乎在使用 VS 代码扩展 - ESLint v2.2.2。
eslintrc.js:
module.exports = {
root: true,
env: {
'vue/setup-compiler-macros': true,
node: true,
},
extends: [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/typescript/recommended',
],
parserOptions: {
ecmaVersion: 2020,
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
},
}
如有任何想法,我们将不胜感激。
我有同样的问题,已通过配置解决
globals: {
defineProps: "readonly",
defineEmits: "readonly"
}
offical guide来了,不知道'vue/setup-compiler-macros': true,
为什么不行
你可以查看
你基本上需要:
- 在您的终端上通过 运行
npm uni -D babel-eslint
删除babel-eslint
。 - 通过 运行
npm i -D @babel/eslint-parser
在您的终端上安装@babel/eslint-parser
。 - 使用以下内容更新 ESLint 配置中的
env
行(可以在.eslintrc.js
、.eslintrc.json
或package.json
中):
env: {
node: true,
'vue/setup-compiler-macros': true,
},
- 使用以下内容更新 ESLint 配置中的
parserOptions
行:
parserOptions: {
parser: '@babel/eslint-parser',
ecmaVersion: 2018,
requireConfigFile: false, // This will prevent Babel from looking for a config file you possibly don’t have or need.
},
- 如果
parserOptions
外面有parser
行,您可以将其删除以避免冲突。
您需要将eslint-plugin-vue 升级到版本8,它根据发行说明添加了它。 硒也 https://github.com/vuejs/eslint-plugin-vue/pull/1685
使用配置创建 eslintrc.is 文件对我不起作用。
我在没有 运行 任何升级的情况下修复了这个错误,我所做的只是在 package.json 文件的 eslintConfig 部分添加“vue/setup-compiler-macros: true”
即:
"eslintConfig": {
...
"env": {
node: true,
"vue/setup-compiler-macros": true
}
}