{"record":{"id":"d6ddb8a5ac3975d5","repo":"oxc-project/oxc","slug":"module-module-name-is-imported-more-than-once","errorCode":null,"errorMessage":"Module '{module_name}' is imported more than once in this file","messagePattern":"Module '(.+?)' is imported more than once in this file","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/no_duplicates.rs","lineNumber":36,"sourceCode":"    fixer::{RuleFix, RuleFixer},\n    module_record::{ImportImportName, RequestedModule},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_duplicates_diagnostic<I>(\n    module_name: &str,\n    first_import: Span,\n    other_imports: I,\n) -> OxcDiagnostic\nwhere\n    I: IntoIterator<Item = Span>,\n{\n    const MAX_MODULE_LEN: usize = 16;\n\n    let message = if module_name.len() > MAX_MODULE_LEN {\n        Cow::Borrowed(\"Modules should not be imported multiple times in the same file\")\n    } else {\n        Cow::Owned(format!(\"Module '{module_name}' is imported more than once in this file\"))\n    };\n    let labels = std::iter::once(first_import.primary_label(\"It is first imported here\"))\n        .chain(other_imports.into_iter().map(LabeledSpan::underline));\n\n    OxcDiagnostic::warn(message)\n        .with_labels(labels)\n        .with_help(\"Merge these imports into a single import statement\")\n}\n\n// <https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-duplicates.md>\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoDuplicates {\n    /// When set to `true`, prefer inline type imports instead of separate type import\n    /// statements for TypeScript code.\n    ///\n    /// Examples of **correct** code with this option set to `true`:\n    /// ```typescript","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/no_duplicates.rs#L18-L54","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nimport a from 'lodash';\nimport { debounce } from 'lodash';\n\n// after\nimport a, { debounce } from 'lodash';","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"import/no-duplicates\": [\"warn\", { \"preferInline\": true }] } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["lint","oxlint","imports","duplicate-imports","autofix","style"],"backgroundTag":"duplicate-imports","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}