我已经尝试了一段时间来获取 @babel/plugin-proposal-class-properties
与 @babel/eslint-parser
完美配合的插件和 eslint
没有成功。
这是我的.eslintrc.js
:
...
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 11,
"requireConfigFile": false,
},
"plugins": [
"@babel",
],
...
这些是相关的安装包:+-- @babel/core@7.11.1
+-- @babel/eslint-parser@7.11.3
+-- @babel/eslint-plugin@7.11.3
+-- @babel/plugin-proposal-class-properties@7.10.4
+-- eslint@7.7.0
在此配置下,ESLint 错误并显示以下消息:
Parsing error: \eg\example.js: Support for the experimental syntax 'classPrivateProperties' isn't currently enabled (xx:yy): (Fatal)
但是如果我添加 @babel/plugin-proposal-class-properties
至plugins
在 .eslintrc.js
像这样: "plugins": [
"@babel",
"@babel/plugin-proposal-class-properties",
],
我收到此错误:Error while running ESLint: Failed to load plugin '@babel/plugin-proposal-class-properties' declared in '.eslintrc.js': Cannot find module '@babel/eslint-plugin-plugin-proposal-class-properties'.
这似乎不是为
@babel/eslint-parser
声明插件的正确方法在 .eslintrc.js
.不过,我怀疑这可能是由于这句话 here :
@babel/eslint-parser
also supports applying Babel configuration through your ESLint configuration.
所以我的问题是:
是否真的可以在
.eslintrc
中声明 babel 插件? ?如果是这样,具体如何?
最佳答案
它实际上比我想象的要简单......
所以事实证明,自从 @babel/plugin-proposal-class-properties
是一个 babel 插件,需要在 plugins
中声明babel 配置的属性。根据the documentation of @babel/eslint-parser
, 可以用 babelOptions
传入属性(property)。
因此它真的很简单:
...
"parserOptions": {
...
"babelOptions": {
"plugins": [
"@babel/plugin-proposal-class-properties",
...
],
},
},
"plugins": [
"@babel",
],
...
关于javascript - 在 .eslintrc 中为 @babel/eslint-parser 声明 babel 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63482553/