在.eslintrc中声明@ babel / eslint-parser的babel插件 [英] Declaring babel plugins for @babel/eslint-parser in .eslintrc
问题描述
我已经尝试了一段时间,以获取 @ babel / plugin-proposal-class-properties
插件与 @babel配合使用/ eslint-parser
和 eslint
没有成功。
I've been trying for a while now to get @babel/plugin-proposal-class-properties
plugin to work nicely with @babel/eslint-parser
and eslint
without success.
这是我的。 eslintrc.js
:
...
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 11,
"requireConfigFile": false,
},
"plugins": [
"@babel",
],
...
这些是已安装的相关软件包:
And these are the related installed packages:
+-- @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出现以下错误:
Under this configuration, ESLint errors with this message:
Parsing error: \eg\example.js: Support for the experimental syntax 'classPrivateProperties' isn't currently enabled (xx:yy): (Fatal)
但是如果我添加 @ babel / plugin-proposal-class-properties
到 .eslintrc.js $ c $中的
插件
c>像这样:
But if I add @babel/plugin-proposal-class-properties
to plugins
in .eslintrc.js
like this:
"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'.
似乎这不是声明<$ c $的插件的正确方法在 .eslintrc.js
中的c> @ babel / eslint-parser 中。尽管如此,我怀疑由于此引用此处:
It seems like this isn't the correct way to declare plugins for @babel/eslint-parser
in .eslintrc.js
. Still, I suspect it is possible due to this quote here:
@ babel / eslint-parser
也支持应用Babel通过您的ESLint配置进行配置。
@babel/eslint-parser
also supports applying Babel configuration through your ESLint configuration.
所以我的问题是:
实际上可以在其中声明babel插件吗? .eslintrc
?
推荐答案
实际上比我想象的要简单...
It's actually simpler than I thought...
事实证明,由于 @ babel / plugin-proposal-class-properties
是babel插件,因此需要在 plugins中声明属性。根据 <$ c的文档$ c> @ babel / eslint-parser
,这些可以通过 babelOptions
属性传递。
So it turns out that since @babel/plugin-proposal-class-properties
is a babel plugin, it needs to be declared in the plugins
property of babel's configuration. According to the documentation of @babel/eslint-parser
, those can be passed in with babelOptions
property.
因此,它真的是如此简单:
Therefore it's really as simple as this:
...
"parserOptions": {
...
"babelOptions": {
"plugins": [
"@babel/plugin-proposal-class-properties",
...
],
},
},
"plugins": [
"@babel",
],
...
这篇关于在.eslintrc中声明@ babel / eslint-parser的babel插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!