oxc-project/oxc · warning

'{module_name}' import is duplicated

Error message

'{module_name}' import is duplicated

What it means

This diagnostic comes from the `no_duplicate_imports` rule in oxlint. The rule reads the module record that the parser builds for the file. When two import statements resolve to the same module name, it reports the second one as duplicated. The report labels both the duplicate import and the earlier import that it can merge with.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs:21

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_str::CompactStr;
use schemars::JsonSchema;
use serde::Deserialize;

use crate::{
    context::LintContext,
    module_record::{ExportImportName, ImportImportName},
    rule::{DefaultRuleConfig, Rule},
};

fn no_duplicate_imports_diagnostic(
    module_name: &str,
    span: Span,
    previous_span: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("'{module_name}' import is duplicated"))
        .with_help("Merge the duplicated import into a single import statement")
        .with_labels([
            span.label("This import is duplicated"),
            previous_span.label("Can be merged with this import"),
        ])
}

fn no_duplicate_exports_diagnostic(
    module_name: &str,
    span: Span,
    previous_span: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("'{module_name}' export is duplicated"))
        .with_help("Merge the duplicated exports into a single export statement")
        .with_labels([
            span.label("This export is duplicated"),
            previous_span.label("Can be merged with this"),
        ])

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Merge the two statements into one: `import { a, b } from './util';`.
  2. Run the editor command 'organize imports', which merges duplicates.
  3. Align path aliases so one module has exactly one spelling in the file.
  4. Suppress with `// oxlint-disable-next-line no-duplicate-imports` when a merge would break a loader.

Example fix

// before
import { read } from './fs.js';
import { write } from './fs.js';

// after
import { read, write } from './fs.js';
Defensive patterns

Strategy: validation

Validate before calling

// collect import sources and find repeats
const srcs = [...src.matchAll(/import[\s\S]*?from\s+['"]([^'"]+)['"]/g)].map(m => m[1]);
const dup = srcs.filter((s, i) => srcs.indexOf(s) !== i);
if (dup.length) throw new Error('duplicate imports: ' + [...new Set(dup)].join(', '));

Prevention

When it happens

Trigger: Two import declarations with the same source string: `import { a } from './util'; import { b } from './util';`. The rule compares module names in the module record and fires once per extra statement.

Common situations: Several people add imports to the same file over time. An IDE auto-import adds a second statement instead of merging. Path aliases change, and two spellings of one module coexist after a partial rename.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/ff4a167289003d28. Report an issue: GitHub.