Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration for rule "import/no-cycle" is invalid #2331

Closed
aachauhan2009 opened this issue Nov 9, 2020 · 23 comments · Fixed by City-of-Helsinki/helsinki-design-system#579

Comments

@aachauhan2009
Copy link

aachauhan2009 commented Nov 9, 2020

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.

@flemay
Copy link

flemay commented Nov 9, 2020

I have the same issue.

Replacing with Infinity works like version 14.2.0

When comparing version 14.2.1 with 14.2.0 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: '∞' }],

@artkon
Copy link

artkon commented Nov 9, 2020

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.

@ljharb
Copy link
Collaborator

ljharb commented Nov 9, 2020

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)

@ljharb ljharb closed this as completed Nov 9, 2020
@MikeTaylor

This comment has been minimized.

@ljharb

This comment has been minimized.

@MikeTaylor

This comment has been minimized.

dplumb94 added a commit to Cargill/grid that referenced this issue Nov 9, 2020
There appears to have been a breaking change in a minor ESLing version.
Updating this dependency should fix the issue.

airbnb/javascript#2331

Signed-off-by: Darian Plumb <dplumb@bitwise.io>
dplumb94 added a commit to Cargill/grid that referenced this issue Nov 9, 2020
There appears to have been a breaking change in a minor ESLing version.
Updating this dependency should fix the issue.

airbnb/javascript#2331

Signed-off-by: Darian Plumb <dplumb@bitwise.io>
shannynalayna added a commit to shannynalayna/splinter-ui that referenced this issue Nov 9, 2020
Breaking change occurred in a minor ESLint version. Update to this
dependency fixes the bug.

Issue: airbnb/javascript#2331

Signed-off-by: Shannyn Telander <telander@bitwise.io>
shannynalayna added a commit to shannynalayna/splinter-ui that referenced this issue Nov 9, 2020
Breaking change occurred in a minor ESLint version. Update to this
dependency fixes the bug.

Issue: airbnb/javascript#2331

Signed-off-by: Shannyn Telander <telander@bitwise.io>
keshav-c added a commit to keshav-c/React-Calculator that referenced this issue Nov 12, 2020
This solves the github actions linter error by changing the
eslint-plugin-import version as described in
airbnb/javascript/issues/2331
bertil291utn added a commit to bertil291utn/linters-config that referenced this issue Nov 12, 2020
Update this version to avoid "import-nocycle" [issue](airbnb/javascript#2331)
binodpant added a commit to openedx/frontend-build that referenced this issue Nov 16, 2020
Why: need 2.22.1 minimum, to address issue with
          import/no-cycles rule in eslint. Was encountered
          while working on
          openedx/frontend-enterprise#21
Ref: airbnb/javascript#2331 (comment)
@morewings
Copy link

I have this problem too, but I have "eslint-plugin-import" updated to "2.22.1".

@mtmacdonald
Copy link

I also still have this problem with "eslint-plugin-import" updated to "2.22.1".

@artkon
Copy link

artkon commented Nov 20, 2020

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.

webbertakken pushed a commit to game-ci/unity-request-activation-file that referenced this issue Jan 11, 2021
* fix: configuration for rule "import/no-cycle" is invalid

airbnb/javascript#2331 (comment)

* feat: support custom image
@KenSkudderPWW
Copy link

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.

@ljharb
Copy link
Collaborator

ljharb commented Feb 13, 2021

@KenSkudderPWW i'm really not sure; if all those are installed, then this message shouldn't be possible.

@KenSkudderPWW
Copy link

@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.

stvnjacobs added a commit to stvnjacobs/pools.piedao.org that referenced this issue Mar 6, 2021
This resolves the following error that occurs when running `yarn run lint`

```
yarn run fmt
...
Oops! Something went wrong! :(

ESLint: 7.20.0

Error: .eslintrc.js » eslint-config-airbnb-base » /home/steven/workspace/pools.piedao.org/node_modules/eslint-config-airbnb-base/rules/imports.js:
	Configuration for rule "import/no-cycle" is invalid:
	Value "∞" should be integer.
```

Grabbed from here: airbnb/javascript#2331 (comment)
@flying-sheep
Copy link

flying-sheep commented Mar 10, 2021

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:
    - eslint@7.21.0
    - eslint-config-airbnb-base@14.2.1
    - eslint-plugin-import@2.22.1

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
        }
      }
    }
  ]
}

@ljharb
Copy link
Collaborator

ljharb commented Mar 10, 2021

Commit hooks can sometimes use global installs and not local ones; what happens with an actual local eslint CLI command?

@flying-sheep
Copy link

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.

@ljharb
Copy link
Collaborator

ljharb commented Mar 10, 2021

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.

@flying-sheep
Copy link

“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 …

@ljharb
Copy link
Collaborator

ljharb commented Mar 10, 2021

locally means only one thing: in node_modules.

@GibzonDev
Copy link

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.

@huntzinger92
Copy link

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!

@ljharb
Copy link
Collaborator

ljharb commented Aug 1, 2021

Sadly i believe react-scripts fails to properly use ^ semver ranges, and so is unable to automatically receive bugfixes and security updates.

@umbrellait-alexander-gusev

I have updated eslint-plugin-import to version 2.22.1.
Then removed node_modules - rm -rf ./node_modules
Then installed them - npm i
It worked for me. Thank you!

ameliabradley pushed a commit to ameliabradley/grid that referenced this issue Jul 26, 2022
Breaking change occurred in a minor ESLint version. Update to this
dependency fixes the bug.

Issue: airbnb/javascript#2331

Signed-off-by: Shannyn Telander <telander@bitwise.io>
@rupenshethXeb
Copy link

I have updated eslint-plugin-import to version 2.22.1. Then removed node_modules - rm -rf ./node_modules Then installed them - npm i It worked for me. Thank you!

This worked for me. Earlier face the issue of eslint version but later following the above steps, it got resolved. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.