Skip to content

import/no-duplicates Suspicious

What it does

Reports if a resolved path is imported more than once in the same module. This helps avoid unnecessary duplicate imports and keeps the code clean.

Why is this bad?

Importing the same module multiple times can lead to redundancy and unnecessary complexity. It also affects maintainability, as it might confuse developers and result in inconsistent usage of imports across the code.

Examples

Examples of incorrect code for this rule:

javascript
import { foo } from "./module";
import { bar } from "./module";

import a from "./module";
import { b } from "./module";

Examples of correct code for this rule:

typescript
import { foo, bar } from "./module";

import * as a from "foo"; // separate statements for namespace imports
import { b } from "foo";

import { c } from "foo"; // separate type imports, unless
import type { d } from "foo"; // `preferInline` is true

References

Released under the MIT License.