question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`no-cycle` does not raise error on circular dependency?

See original GitHub issue

There are three files:

src/a.ts:

import y from "./b";

const x: number = y + 1;
export default x;

src/b.ts:

import x from "./a";

const y: number = x + 1;
export default y;

src/c.ts:

import x from "./a";
import y from "./b";

console.log(x, y);

and the configuration is:

{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript"
  ],
  "plugins": [
    "@typescript-eslint",
    "import"
  ],
  "parser": "@typescript-eslint/parser",
  "settings": {
    "import/parsers": {
      "@typescript-eslint/parser": [
        ".ts",
        ".tsx"
      ]
    }
  },
  "rules": {
    "import/no-cycle": [
      "error",
      {
        "maxDepth": 10,
        "ignoreExternal": true
      }
    ]
  }
}

Given the command

$ yarn eslint src\c.ts
yarn run v1.22.10
$ D:\Projects\graphact\server\node_modules\.bin\eslint src\c.ts
Done in 2.03s.

no error occurs while c.ts imports both a.ts and b.ts, which are circular importing each other!

Is it the desired behavior, or I missed something?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:14
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
Yaojiancommented, Mar 13, 2021

Still not working after adding import/extensions.

I setup a test project on https://github.com/Yaojian/no-cycle-test

1reaction
Slapboxcommented, May 28, 2021

Check out #2103.

The next step here, I think, is to install eslint-plugin-import via setting a specific commit ID in the package.json and to test if we can find a commit where either of these bugs were not present. There’s not many commits, so most of the work involved here (should) be just starting/stopping costs of taking on a next task and waiting for npm installs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-cycle does not raise error on circular dependency? #2004
no error occurs while c.ts imports both a.ts and b.ts , which are circular importing each other! Is it the desired behavior, ...
Read more >
How to config the `no-cycle` rule in eslint-plugin-import for ...
It won't raise the lint error in c.ts file because the circular dependency is between a.ts and b.ts . ESLint no-cycle rule description....
Read more >
How to fix nasty circular dependency issues once and for all in ...
Luckily, as I will demonstrate below, there is a consistent way in which these dependency issues can be fixed. The case. The module...
Read more >
How to Analyze Circular Dependencies in ES6? - Railsware
It is caused by circular dependencies that cannot be resolved synchronously by webpack. One is undefined, hence the error.
Read more >
API with NestJS #61. Dealing with circular dependencies
The rule that we want is called import/no-cycle, and it ensures that no circular dependencies are present between our files. In our NestJS ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found