Skip to content

Improve warning message for circular dependencies #243

@SarahIsWeird

Description

@SarahIsWeird

I ran into a weird issue with circular dependencies, and the warning (if you can even call it that), didn't really jump out to me as something I should check out.

// src/lib/foo.ts
import { bar } from './bar';

export const foo = 1
export const allValues = [bar];

// src/lib/bar.ts
import { foo } from './foo';

export const bar = foo + 1;
Circular dependency: src/lib/foo.ts -> src/lib/bar.ts -> src/lib/foo.ts

Of course, in this simple example, it's immediately clear that a circular dependency is present. However, my project is getting quite big, and I don't keep a mental map of all the files and their connections in mind while working on it. Also, since I'm not that familiar with JS tooling, I would have thought that it would be reordered to resolve the circular dependency. As the programmer, it's trivial to do this by hand, but presumably handling this automatically is rather difficult.

With this in mind, I'd like to propose an error message along with a flag to turn the error into a warning for backwards compatibility, something akin to this:

Error: circular dependency found: src/lib/foo.ts -> src/lib/bar.ts -> src/lib/foo.ts
If you want to ignore this error, pass --ignore-circular-dependencies. Warning: things may break unexpectedly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions