Eslint 错误,规则“import/no-cycle”的配置无效

Posted

技术标签:

【中文标题】Eslint 错误,规则“import/no-cycle”的配置无效【英文标题】:Eslint error, configuration for rule "import/no-cycle" is invalid 【发布时间】:2021-02-23 16:14:41 【问题描述】:

运行我的 lint 脚本 "lint": "eslint --ext .js .",给我这个错误:

错误:.eslintrc » eslint-config-airbnb » //node_modules/eslint-config-airbnb-base/index.js » //node_modules/eslint-config-airbnb-base/rules/imports.js: 规则“import/no-cycle”的配置无效: 值“∞”应该是整数。

包.json:

 "devDependencies": 
    "@babel/core": "7.9.0",
    "@babel/runtime": "7.9.2",
    "@babel/parser": "7.11.5",
    "@react-native-community/eslint-config": "1.0.0",
    "babel-eslint": "10.1.0",
    "babel-jest": "25.2.3",
    "babel-plugin-module-resolver": "4.0.0",
    "babel-preset-react-native": "4.0.1",
    "bluebird": "3.7.2",
    "catharsis": "0.8.11",
    "cross-env": "7.0.2",
    "escape-string-regexp": "2.0.0",
    "eslint": "6.8.0",
    "eslint-config-airbnb": "18.1.0",
    "eslint-config-react-native": "4.0.0",
    "eslint-plugin-import": "2.20.1",
    "eslint-plugin-jsx-a11y": "6.2.3",
    "eslint-plugin-react": "7.19.0",
    "eslint-plugin-react-hooks": "3.0.0",
    "eslint-plugin-react-native": "3.8.1",
    "husky": "4.2.3",
    "jest": "25.2.3",
    "jest-fetch-mock": "3.0.3",
    "jest-junit": "10.0.0",
    "jest-transform-stub": "2.0.0",
    "js2xmlparser": "4.0.1",
    "jsdoc": "3.6.6",
    "klaw": "3.0.0",
    "markdown-it": "10.0.0",
    "markdown-it-anchor": "5.2.7",
    "marked": "0.8.2",
    "metro-react-native-babel-preset": "0.59.0",
    "mkdirp": "1.0.4",
    "node": "12.10.0",
    "npm-check": "5.9.2",
    "react-test-renderer": "16.13.1",
    "redux-mock-store": "1.5.4",
    "requizzle": "0.2.3",
    "strip-json-comments": "3.1.0",
    "taffydb": "2.6.2",
    "underscore": "1.10.2"
  ,

【问题讨论】:

【参考方案1】:

根据这个帖子https://github.com/airbnb/javascript/issues/2331#issuecomment-724114465

您需要将eslint-plugin-import 更新为支持 值的^2.22.1

【讨论】:

【参考方案2】:

在这里分享我发现的解决此问题的方法。 所有对等依赖项均已安装且版本正确,但仍然出现此错误。

我将node_modules/eslint-config-airbnb-base/rules/imports.js "∞" 更改为整数以继续调试。下一次运行显示此错误,ESLint couldn't determine the plugin "import" uniquely.,这是根本问题。事实证明,eslint 会从祖先目录加载所有配置,如此处所述,https://github.com/eslint/eslint/issues/13385#issuecomment-641252879。

我将"root":true 添加到 .eslint 配置文件并将更新转换为node_modules/eslint-config-airbnb-base/rules/imports.js。它现在运行。希望对其他人有所帮助。

【讨论】:

以上是关于Eslint 错误,规则“import/no-cycle”的配置无效的主要内容,如果未能解决你的问题,请参考以下文章

Eslint 错误,规则“import/no-cycle”的配置无效

ESLint规范

eslint规则

未找到规则“导入/扩展”的 ESLint 定义

如何在 React Native 默认 eslint 配置中删除 eslint 单引号规则?

需要返回类型的箭头函数的 ESLint 规则