Skip to content

import/no-cycle does not detect some cycles with side-effect imports #3147

Open
@guillaumebrunerie

Description

@guillaumebrunerie

Here is the setup (https://codesandbox.io/p/devbox/my57j6):

// a.js
import "./b";
export const f = () => globalThis.x;

// b.js
import "./c";

// c.js
import { f } from "./a";

globalThis.x = f();

This seems like a cycle to me (a.js expects globalThis.x to be set given that it imports b.js which imports c.js which sets it, but c.js uses an import from a.js in order to set globalThis.x).
Yet this is not detected as a cycle by eslint-plugin-import. Note that changing a.js to import ./c instead of ./b is detected as a cycle, so it seems to be the indirection introduced by b.js which confuses no-cycle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions