Dependency cycle detected import/no-cycle
See original GitHub issueHello,
After an update from ‘2.22.1’ to ‘2.23.0’ I have this error
Dependency cycle detected import/no-cycle
I’m trying to import a TypeScript Type like this:
./Bar.ts
import useBar from './useBar';
export type Bar = {
msg: string
}
./useBar.ts
import type { Bar } from './Bar';
Previously import type even if it was cycled import worked.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (3 by maintainers)
Top Results From Across the Web
dependency cycle detected import/no-cycle
I am trying to set up API endpoints in ES6. In my main server file, I tried to import the router module but...
Read more >eslint-plugin-import/no-cycle.md at main
Ensures that there is no resolvable path back to this module via its dependencies. This includes cycles of depth 1 (imported module imports...
Read more >Dependency cycle detected in React component index file
So I read the docs for eslint's "import/no-cycle" rule: "Ensures that there is no resolvable path back to this module via its dependencies."...
Read more >[Solved]-dependency cycle detected import/no-cycle-node.js
[Solved]-dependency cycle detected import/no-cycle-node.js ... This could be a direct reference (A -> B -> A) issue, which even you might be doing....
Read more >Understanding import/no-cycle problem in eslint
The exact error thrown is: ESLint: Dependency cycle via ../types:7=>./Jobs:1(import/no-cycle) . File 1. jobs/Jobs. import { AuthJobs } from './ ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
An option would be great – I would love to have this rule included. And I have a feeling that this has broken eslint for a lot of people ❤️
As for
import type
creating runtime issues, it won’t, even with enums and classes, though usingimport
with an enum will. I’ve created a small test repo that demonstrates this here.In the documentation for
import type
, they say:However, there is a very poorly worded section:
It can lead to the impression that
import type
will have a value at runtime, but looking at the example below, it’s about the inability to extend the class as you would with an interface usingimport type
.If you’re good with a flag, I’m happy to take a look and send over a pull request
Sorry, @ljharb, but this is wrong. The purpose of this rule is to avoid possible issues at runtime with circular dependencies. Using
import type
will never lead to that. Moreover, I disagree about this always being bad architecture when it comes to importing types. There are plenty of cases when this is more than appropriate.At the very least, it should be configurable to exclude
import type
.The makers of Madge know and understand that.
In any case, this has rendered this check useless for me because of this, which is actually really unfortunate. So, turning this rule off and integrating Madge into CI flow.