eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

'import/no-cycle' issue

Open sshmyg opened this issue 3 years ago • 25 comments

Hi After updating eslint and eslint-plugin-import to latest version (eslint 8.5.0, eslint-plugin-import 2.25.3), in VSCode and via terminal also I get errors from the rule import/no-cycle. Nothing was changed, just bumped packages versions. Prev versions was ("eslint": "7.32.0", "eslint-plugin-import": "2.24.2").

Will try to make sandbox project to reproduce the problem.

Some additional info here https://github.com/import-js/eslint-plugin-import/issues/2260

sshmyg avatar Dec 31 '21 11:12 sshmyg

With before update versions of packages, there are no any errors about import/no-cycle.

Before update

"@typescript-eslint/eslint-plugin": "4.30.0",
"@typescript-eslint/parser": "4.30.0",
"eslint": "7.32.0",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-jest": "24.4.0",
"eslint-plugin-promise": "5.1.1",
"typescript": "4.4.4",

After update:

"@typescript-eslint/eslint-plugin": "5.8.1",
 "@typescript-eslint/parser": "5.8.1",
"eslint": "8.5.0",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-jest": "25.3.2",
"eslint-plugin-promise": "6.0.0",
"typescript": "4.5.4",

sshmyg avatar Dec 31 '21 12:12 sshmyg

Checks with eslint for all project took ~ 5min with old packages versions. With new ones ~ 47min.

sshmyg avatar Dec 31 '21 12:12 sshmyg

Can you try eslint 7.32.0 with the latest version of the plugin?

ljharb avatar Dec 31 '21 15:12 ljharb

Can you try eslint 7.32.0 with the latest version of the plugin?

Doesn't work :(

sshmyg avatar Jan 02 '22 18:01 sshmyg

Ok, hmm - any chance you could figure out the exact plugin version where the problem started?

ljharb avatar Jan 02 '22 18:01 ljharb

Will try to get more info.

sshmyg avatar Jan 02 '22 18:01 sshmyg

Works with this versions

"eslint": "7.32.0",
"eslint-plugin-import": "2.24.2",

Got such error from eslint Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/util/glob-util' is not defined by "exports" in /node_modules/eslint/package.json with versions

"eslint": >="8.0.0",
"eslint-plugin-import": "2.24.2",

Cycle rule errors with versions

"eslint": >="8.0.0",
"eslint-plugin-import": >="2.25.0",

So can assume, cycle issue started with import plugin version 2.25.0.

sshmyg avatar Jan 02 '22 19:01 sshmyg

Indeed, v2.25 is the first version of the plugin to support eslint 8. I was hoping with eslint 7, you could confirm that v2.25.0 also breaks.

ljharb avatar Jan 02 '22 21:01 ljharb

Using eslint 7.32.0 2.25.3 was fine Since 2.25.4 I get the error Dependency cycle via @/router:3 (import/no-cycle)

MartinX3 avatar Jan 13 '22 14:01 MartinX3

@MartinX3 and are you sure that's not actually a real cycle being reported?

ljharb avatar Jan 13 '22 17:01 ljharb

@ljharb Luckily yes. The 2 mentioned static typescript classes don't inject each other.

MartinX3 avatar Jan 13 '22 17:01 MartinX3

@MartinX3 could you provide a repro? ideally a small repo that shows the problem. (not sure what "inject" means; there's no injection in JS around modules, only "function arguments")

ljharb avatar Jan 13 '22 17:01 ljharb

Login.vue does a

import Fetch from "@/utils/Fetch";
import Session from "@/utils/Session";

Registration.vue does a

import Fetch from "@/utils/Fetch";

Course.vue does a

import Fetch from "@/utils/Fetch";

Session.ts does a

import Fetch from "@/utils/Fetch";

And that's what the issue tells me in the terminal. Downgrading from 2.25.4 back to 2.25.3 fixes the issue. The application works without any problem.

MartinX3 avatar Feb 12 '22 19:02 MartinX3

Do you have a vue eslint parser?

ljharb avatar Feb 12 '22 20:02 ljharb

From my .eslintrc.js

  parser: "vue-eslint-parser",
  parserOptions: {
    parser: "@typescript-eslint/parser",
  },
  plugins: ["@typescript-eslint"],

My JavaScript project is fine

MartinX3 avatar Feb 12 '22 20:02 MartinX3

so, none of those seem like cycles; what's the exact error in your (non-editor) terminal?

ljharb avatar Feb 12 '22 21:02 ljharb

@ljharb the exact error is

error: Dependency cycle via @/router:5 (import/no-cycle) at src/views/account/checkin/Login.vue:42:1:
  40 | import { Component, Prop } from "vue-property-decorator";
  41 | import ASave from "@/dialogs/crud/ASave";
> 42 | import Fetch from "@/utils/Fetch";
     | ^
  43 | import Session from "@/utils/Session";
  44 | import SessionStorage from "@/utils/SessionStorage";
  45 | import UserAccount from "@/models/entities/user/UserAccount";


error: Dependency cycle via @/utils/Fetch:2=>@/router:5 (import/no-cycle) at src/views/account/checkin/Login.vue:43:1:
  41 | import ASave from "@/dialogs/crud/ASave";
  42 | import Fetch from "@/utils/Fetch";
> 43 | import Session from "@/utils/Session";
     | ^
  44 | import SessionStorage from "@/utils/SessionStorage";
  45 | import UserAccount from "@/models/entities/user/UserAccount";
  46 | 


error: Dependency cycle via @/router:5 (import/no-cycle) at src/views/account/checkin/Registration.vue:48:1:
  46 | import ASave from "@/dialogs/crud/ASave";
  47 | import EHttpStatusCode from "@/models/enums/EHttpStatusCode";
> 48 | import Fetch from "@/utils/Fetch";
     | ^
  49 | import UserAccount from "@/models/entities/user/UserAccount";
  50 | 
  51 | @Component


error: Dependency cycle via @/router:5 (import/no-cycle) at src/views/admin/Course.vue:38:1:
  36 | import ECourseDateType from "@/models/enums/course/date/ECourseDateType";
  37 | import ECourseType from "@/models/enums/course/ECourseType";
> 38 | import Fetch from "@/utils/Fetch";
     | ^
  39 | import ICourseDate from "@/models/entities/course/date/ICourseDate";
  40 | import ICourseDateAdmin from "@/models/entities/admin/course/date/ICourseDateAdmin";
  41 | import ISeminarFSAdmin from "@/models/entities/admin/course/date/ISeminarFSAdmin";


4 errors found.

PS: I use lazy loading in the VueRouter https://router.vuejs.org/guide/advanced/lazy-loading.html component: () => import("@/views/error/Unknown.vue")

MartinX3 avatar Feb 15 '22 12:02 MartinX3

I fixed it my removing the vue-router import from my TypeScript Utils class with my HTTP-Fetch functions. So I only import the router in my main.ts into the vue object and instead of importing it also in my Utils class, I inject this.$router as a parameter with every function execution.

It makes my code bigger and I wonder if I wrote bad code before or it is a bug in this dependency.

MartinX3 avatar Apr 07 '22 17:04 MartinX3

Is your eslint configured to understand the vue extension?

ljharb avatar Apr 07 '22 17:04 ljharb

Yes, it lints .vue files

MartinX3 avatar Apr 07 '22 17:04 MartinX3

right, but have you set the import/extensions setting, so that this plugin can look at them?

ljharb avatar Apr 07 '22 17:04 ljharb

I did not write a "import/extensions". I don't know in which documentation it is written.

The first router import is in the main.ts, the second import, which I removed, was in the Fetch.ts which is imported in .vue files.

MartinX3 avatar Apr 07 '22 17:04 MartinX3

This plugin's readme: https://github.com/import-js/eslint-plugin-import#settings

ljharb avatar Apr 07 '22 18:04 ljharb

Hi Checked latest version of eslint and import plugin. It works, but very very very slow. Was using .ts file with ~ 300 lines of code. Imports lines ~ 20 lines (not much). Compared also result with versions of eslint and import plugin which using right now in project. Results below.

Latest version of eslint and import plugin. ("eslint": "8.14.0", "eslint-plugin-import": "2.26.0")

  • time spent on check 27 sec 🤦‍♂️

Current versions in my project ("eslint": "7.32.0", "eslint-plugin-import": "2.24.2")

  • time spent on check 1.5 sec 🥳

OS - macOS Monterey 12.3.1

sshmyg avatar Apr 29 '22 07:04 sshmyg

right, but have you set the import/extensions setting, so that this plugin can look at them?

I added it, but still the same issue without my workaround.

If I looked correctly vue already added these imports as well in their ecosystem so it isn't needed anyway by the user to add them.

MartinX3 avatar May 04 '22 13:05 MartinX3

This issue has gotten a bit off topic. I'm going to close it.

Those following: please wait until the next release (v2.27.0), and if you're still having troubles after that comes out, please file a new issue with all the details! If you include a repro repo, or make a PR with failing test cases, I can fix your issue much faster. Thanks!

ljharb avatar Aug 27 '22 05:08 ljharb