Sei*_*Sys 5 javascript eslint babeljs
我正在尝试将@babel/plugin-proposal-private-methods插件与ESLint 一起使用,但是,任何使用新功能的代码都会导致此错误:
ESLint:解析错误:此实验语法要求启用解析器插件:'classPrivateMethods'
基于此错误消息,尚不清楚应该在何处启用此插件,并且我找不到有关如何向我添加“解析器插件”的任何说明.eslintrc(如下所示)。
{
"parser": "babel-eslint",
"env": {
"browser": true,
"jquery": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"plugins": [
"react"
],
"parserOptions": {
"sourceType": "script",
"ecmaVersion": 6,
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"camelcase": 0,
"curly": 0,
"wrap-iife": [
2,
"any"
],
"linebreak-style": 2,
"comma-style": [
2,
"last"
],
"new-cap": 2,
"strict": [
2,
"function"
],
"no-undef": 2,
"no-unused-vars": 0,
"no-console": 0,
"react/prop-types": 0
}
}
Run Code Online (Sandbox Code Playgroud)
如何启用此解析器插件?
Gra*_*ham 18
babel-eslint repo 中存在一个问题:https : //github.com/babel/babel-eslint/pull/523
它最近已解决,并在源代码中发布了修复程序babel-eslint@11.0.0-beta.0
一旦babel-eslint@11.0.0可用,您就可以升级,插件将从您的 Babel 配置文件中加载。
// babel.config.js
module.exports = {
plugins: [
"@babel/plugin-proposal-private-methods"
]
};
Run Code Online (Sandbox Code Playgroud)
小智 9
现在已经十月了,但babel-eslint@11.0.0还没有发布。同时,您可以应用下面的解决方案,该解决方案目前对我有用
@babel/plugin-proposal-class-properties@babel/plugin-proposal-private-methods@babel/eslint-parserclassPrivateProperties和classPrivateMethods.eslintrc.jsonpackage.json
.eslintrc.js

结果:
我现在可以在我的代码中使用私有方法而不会出现 eslint 错误

Feel free to comment if you get any problem implementing this solution.
Peace!
| 归档时间: |
|
| 查看次数: |
1189 次 |
| 最近记录: |