Configuration for rule "import/no-cycle" is invalid
Oops! Something went wrong! :(
ESLint: 7.0.0
Error: .eslintrc » eslint-config-airbnb » /node_modules/eslint-config-airbnb-base/index.js » /node_modules/eslint-config-airbnb-base/rules/imports.js: Configuration for rule "import/no-cycle" is invalid: Value "∞" should be integer.
My package json devDependency.
"@babel/core": "7.9.6",
"@babel/runtime": "7.9.6",
"@react-native-community/eslint-config": "0.0.5",
"@testing-library/jest-native": "3.1.0",
"@testing-library/react-native": "5.0.3",
"babel-eslint": "10.1.0",
"babel-jest": "24.8.0",
"babel-plugin-inline-import": "3.0.0",
"eslint": "7.0.0",
"eslint-config-airbnb": "18.1.0",
"eslint-config-prettier": "6.10.0",
"eslint-import-resolver-react-native": "0.2.0",
"eslint-plugin-import": "2.20.1",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-prettier": "3.1.2",
"eslint-plugin-react": "7.19.0",
This has started occurring from today only. It was working last week.
I have the same issue.
Replacing ∞ with Infinity works like version 14.2.0
When comparing version 14.2.1 with 14.2.0 https://github.com/airbnb/javascript/compare/eslint-config-airbnb-base-v14.2.0...eslint-config-airbnb-base-v14.2.1
- 'import/no-cycle': ['error', { maxDepth: Infinity }],
+ 'import/no-cycle': ['error', { maxDepth: '∞' }],
eslint-config-airbnb-base has a
"peerDependencies": {
"eslint": "^5.16.0 || ^6.8.0 || ^7.2.0",
"eslint-plugin-import": "^2.22.1"
},
so update your eslint-plugin-import to ^2.22.1 version, which supports "∞" symbol.
It works for me.
Run npm ls - if your peer dep versions are wrong, your dep graph is invalid, and nothing can be expected to work. Specifically, ensure your eslint plugins are updated (and nothing in your package.json should lack a ^, pinning is achieved with a lockfile, not with package.json)
This kind of issue is why I hate hate hate the Node ecosystem. Someone decides it would be cute to use a literaly infinity symbol in a config file, doesn't think through the implications, and bam lint stops working. I wonder what proportion of all my "work" time is spent on tripping over, diagnosing, and working around totally avoidable problems like this? sigh
@MikeTaylor thats not actually what happened. eslint had a breaking change in a minor version, so that Infinity no longer was accepted, and in response, the import plugin added the infinity symbol as a string so as to not screw over static config users.
The issue is that updating anything, without updating its peer deps, is broken and your own mistake. Any time npm ls exits nonzero, your dep graph is invalid and nothing can be expected to work. In this package’s case, the readme itself gives you explicit install instructions which this user clearly did not follow.
Thanks, @ljharb, for that background, and my apologies to the eslint-config-airbnb-base people for falsely blaming them.
I send no compliments to the people who made a breaking change in a minor release of ESLint :-)
I have this problem too, but I have "eslint-plugin-import" updated to "2.22.1".
I also still have this problem with "eslint-plugin-import" updated to "2.22.1".
I also still have this problem with "eslint-plugin-import" updated to "2.22.1".
Try to remove node_modules and install it from scratch.
Also run npm ls, to check your peer dep versions.
I have just encountered this issue today as well. I have eslint-plugin-import updated to 2.22.1 as well. Here's my package.json file:
{
"name": "test",
"version": "1.0.0",
"main": "js/index.jsx",
"license": "MIT",
"scripts": {
"watch": "npm run development -- --watch",
"build": "npm run production",
"development": "NODE_ENV=development webpack",
"production": "NODE_ENV=production webpack",
"lint": "eslint js/src/ --ext .js --ext .jsx"
},
"dependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/preset-env": "^7.12.16",
"@babel/preset-react": "^7.12.13",
"babel-loader": "^8.2.2",
"eslint": "^7.2.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react-hooks": "^4",
"webpack": "^5.21.2",
"webpack-cli": "^4.5.0"
}
}
Here's my .eslintrc.json file:
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"plugin:react/recommended",
"airbnb"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
}
}
I should also note that I arrived at this non-functional configuration by running yarn run eslint --init and making the following selections:
✔ How would you like to use ESLint? · style
✔ What type of modules does your project use? · esm
✔ Which framework does your project use? · react
✔ Does your project use TypeScript? · No / Yes
✔ Where does your code run? · browser
✔ How would you like to define a style for your project? · guide
✔ Which style guide do you want to follow? · airbnb
✔ What format do you want your config file to be in? · JSON
When eslint prompted me about whether I wanted to install the peer dependencies required by my configuration via npm, I selected "no" (because my project uses yarn to manage dependencies) and installed them myself as dev dependencies with yarn. yarn run eslint --version gives me v7.20.0 in case that's helpful.
@KenSkudderPWW i'm really not sure; if all those are installed, then this message shouldn't be possible.
@KenSkudderPWW i'm really not sure; if all those are installed, then this message shouldn't be possible.
Haha agreed on all fronts: I too am really not sure, and I too don't see how this message could be possible.
For the thing I'm working on I think it'll be alright if I drop enforcement of code style rules, so I've done that in order to get around this, so I'm no longer stuck because of this personally. This issue and a Stack Overflow question which referenced it were the top google results for this problem so I just wanted to post my experience in case anyone else lands here likewise still experiencing the issue.
I get this with pre-commit. I use this pre-commit config:
repos:
- repo: https://github.com/pre-commit/mirrors-eslint
rev: 'v7.21.0'
hooks:
- id: eslint
additional_dependencies:
- [email protected]
- [email protected]
- [email protected]
And confirming that only the correct version of the eslint-plugin-import is installed:
$ cd ~/.cache/pre-commit/repou5udo74e/
$ rg --no-ignore 'maximum dependency depth to traverse'
node_env-system/lib/node_modules/eslint-plugin-import/lib/rules/no-cycle.js
20: description: 'maximum dependency depth to traverse',
$ cat node_env-system/lib/node_modules/eslint-plugin-import/lib/rules/no-cycle.js
...
module.exports = {
meta: {
type: 'suggestion',
docs: { url: (0, _docsUrl2.default)('no-cycle') },
schema: [(0, _moduleVisitor.makeOptionsSchema)({
maxDepth: {
oneOf: [
{
description: 'maximum dependency depth to traverse',
type: 'integer',
minimum: 1 },
{
enum: ['∞'],
type: 'string' }] },
...
Somehow the schema ends up being this? How?
{
"type": "array",
"minItems": 0,
"maxItems": 1,
"items": [
{
"type": "object",
"additionalProperties": false,
"properties": {
"commonjs": {"type": "boolean"},
"amd": {"type": "boolean"},
"esmodule": {"type": "boolean"},
"ignore": {
"type": "array",
"minItems": 1,
"items": {"type": "string"},
"uniqueItems": true
},
"maxDepth": {
"description": "maximum dependency depth to traverse",
"type": "integer",
"minimum": 1
}
}
}
]
}
Commit hooks can sometimes use global installs and not local ones; what happens with an actual local eslint CLI command?
Well, it’s the opposite, somehow it uses the version installed in the project instead of the one in the pre-commit cache directory. Making both match circumvents the problem but it should really try importing locally first as opposed to where the config happens to be.
That's part of the way node and npm and eslint all work, and not something this project can change.
I'm not sure why there is a "pre-commit cache directory"; pre-commit hooks should be using the locally installed node_modules only.
“locally”? That could mean anything. I stepped into the code. It prefers the node_modules in the directory next to the config file, not the one next to its own binary. it goes out of its way to do that and doesn’t rely on the normal node resolution …
locally means only one thing: in node_modules.
I had the same problems, even after checking peer dependencies and updating accordingly. After tearing my hair for an hour, deleting node_modules and installing again, checking the actual code in the node_modules and adding debugging, I decided to restart VS Code. And the error message was gone. Lesson learned.. I hope this can help at least someone else.
I had the same issue, but was only seeing the error in Netlify's pipeline build, not locally. It turns out that react scripts 3.4.1 uses the problematic version of eslint-plugin-import.
In order to fix this issue, I had to upgrade major versions, to react-scripts version 4 (along with major version upgrades to several other packages, including jest and eslint), to accommodate the major version bump. Hope that helps somebody!