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.

[import/no-cycle] do not check node_modules

See original GitHub issue

I’ve got projects with only a very few small files, which I have hard time working on because of no-cycle being too slow (99% of the full eslint time). I wanted to speed-up this time, but I did not want to use maxDepth because I may have some more complex projects and those are the ones where I’d mostly create an unwanted cycle.

While benchmarking the code, I found that there doesn’t seem to be a cache, or the cache is not working. For my project, most of my files import the same very big module (typescript) and this module is analyzed at each import, instead of only at the first time.

But an easy correction which could also improve the speed would be to ignore external modules: there is very, very little chance that a dependency of my project references a file in my project.

For the moment, this should not be a big problem (except for my big typescript dependency), because most dependencies are transpiled into CommonJS and use require instead of import. But if one day, issue #1056 is corrected, or because external dependencies use more and more import, things will become worse.

I made a quick test by directly modifying the code and the time spent by no-cycle fell from more than 2mn to less than 30s.

I can submit a PR if you want. I don’t know if it could be considered an issue (the correction would be a breaking change) or if it the behavior should be controlled by an option of no-cycle.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
sveyretcommented, Mar 6, 2020

I have no time immediately, but I’ll do it within a week or two if no one else takes it before…

2reactions
ljharbcommented, Mar 3, 2020

I’ve thought about it - I’d be willing to accept a PR with an option that specifically ignores cycles in “external” module (https://github.com/benmosher/eslint-plugin-import#importexternal-module-folders)

Read more comments on GitHub >

github_iconTop Results From Across the Web

[import/no-cycle] do not check node_modules #1647 - GitHub
For my project, most of my files import the same very big module ( typescript ) and this module is analyzed at each...
Read more >
dependency cycle detected import/no-cycle - Stack Overflow
In my main server file, I tried to import the router module but I get the error "dependency cycle detected import/no-cycle". Please find...
Read more >
cycle-import-check - npm
ES6 circular import check tool, support js , ts , jsx , tsx and mjs files, and will ignore all node_modules files.
Read more >
node_modules/eslint-plugin-import/docs/rules/no-cycle.md
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 >
The magic behind npm link - Medium
Look for the module in the ./node_modules directory. If it is not there, recursively search in the parent directories' ./node_modules until either the...
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