oxc-project/oxc · warning · OxcDiagnostic
Module '{module_name}' is imported more than once in this fi
Error message
Module '{module_name}' is imported more than once in this file What it means
Short-name variant of the import/no-duplicates message (style category). When the duplicated module's specifier is 16 characters or fewer, the diagnostic names it explicitly, e.g. "Module 'lodash' is imported more than once in this file", and labels the first import plus every duplicate. Grouping is by resolved absolute path, so './mod' and 'mod' in the same directory are the same module.
Source
Thrown at crates/oxc_linter/src/rules/import/no_duplicates.rs:36
fixer::{RuleFix, RuleFixer},
module_record::{ImportImportName, RequestedModule},
rule::{DefaultRuleConfig, Rule},
};
fn no_duplicates_diagnostic<I>(
module_name: &str,
first_import: Span,
other_imports: I,
) -> OxcDiagnostic
where
I: IntoIterator<Item = Span>,
{
const MAX_MODULE_LEN: usize = 16;
let message = if module_name.len() > MAX_MODULE_LEN {
Cow::Borrowed("Modules should not be imported multiple times in the same file")
} else {
Cow::Owned(format!("Module '{module_name}' is imported more than once in this file"))
};
let labels = std::iter::once(first_import.primary_label("It is first imported here"))
.chain(other_imports.into_iter().map(LabeledSpan::underline));
OxcDiagnostic::warn(message)
.with_labels(labels)
.with_help("Merge these imports into a single import statement")
}
// <https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-duplicates.md>
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoDuplicates {
/// When set to `true`, prefer inline type imports instead of separate type import
/// statements for TypeScript code.
///
/// Examples of **correct** code with this option set to `true`:
/// ```typescriptView on GitHub (pinned to e1e7af627c)
Solutions
- Merge the statements into a single import (`import React, { useState } from 'react'`) or run `oxlint --fix` for the built-in merge
- Enable `preferInline` for TS so type imports merge inline instead of staying separate
- Enable `considerQueryString` if loader query strings intentionally differentiate modules
Example fix
// before
import a from 'lodash';
import { debounce } from 'lodash';
// after
import a, { debounce } from 'lodash'; Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json
{ "rules": { "import/no-duplicates": ["warn", { "preferInline": true }] } } Prevention
- Treat import blocks as owned: merge when touching a file's imports anyway
- Enable the autofix in CI (`oxlint --fix` on a dirty branch) for mechanical cleanup
- Remember grouping is by resolved path — './mod' and 'mod' in the same dir are duplicates
When it happens
Trigger: Multiple import statements in one file that resolve to the same path with a specifier ≤ 16 chars (e.g. `import a from 'react'` plus `import { useState } from 'react'`). Emitted from no_duplicates_diagnostic at crates/oxc_linter/src/rules/import/no_duplicates.rs:36.
Common situations: Auto-generated or copy-pasted import blocks; IDE auto-import adding a second statement instead of merging; mixing default/namespace/named imports of one package across statements.
Related errors
- Modules should not be imported multiple times in the same fi
- Could not find the reuseWorker option in ${path}
- Expected '{curr_kind}' syntax before '{prev_kind}' syntax.
- Imports should be sorted alphabetically.
- Member '{name}' of the import declaration should be sorted a
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/d6ddb8a5ac3975d5.
Report an issue: GitHub.