{"record":{"id":"cb0a8a8e6501631c","repo":"oxc-project/oxc","slug":"modules-should-not-be-imported-multiple-times-in-t","errorCode":null,"errorMessage":"Modules should not be imported multiple times in the same file","messagePattern":"Modules should not be imported multiple times in the same file","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/no_duplicates.rs","lineNumber":34,"sourceCode":"use crate::{\n    context::LintContext,\n    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    ///","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/no_duplicates.rs#L16-L52","documentation":"Long-name variant of the import/no-duplicates message (style category). When the same module is imported more than once in a file and the specifier is longer than 16 characters, this generic message is used instead of embedding the module name, keeping the diagnostic readable. Imports are grouped by resolved absolute path (query strings stripped unless considerQueryString), and type imports are kept separate from value imports unless preferInline is set.","triggerScenarios":"Two or more import statements in one file resolving to the same absolute path where the specifier exceeds MAX_MODULE_LEN (16), e.g. `import { a } from './some-long-module-name'` and `import { b } from './some-long-module-name'`. Emitted from no_duplicates_diagnostic at crates/oxc_linter/src/rules/import/no_duplicates.rs:34.","commonSituations":"Large files accumulated by many authors; merging codemod output; webpack loader query strings (`./bar?optionX` vs `./bar?optionY`) being treated as the same module because considerQueryString defaults to false; separate `import type` statements (not duplicates by default).","solutions":["Run `oxlint --fix` (the rule ships a conditional fix that merges the statements) or merge manually into one statement: `import { a, b } from './mod'`","For TypeScript, enable `preferInline: true` so `import { A, type B }` style merging is suggested instead of separate type statements","If query strings are meaningful (webpack loaders), enable `considerQueryString: true` so different options are not flagged"],"exampleFix":"// before\nimport { fetchUser } from './userRepository';\nimport { deleteUser } from './userRepository';\n\n// after\nimport { fetchUser, deleteUser } from './userRepository';","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"import/no-duplicates\": [\"warn\", { \"preferInline\": true, \"considerQueryString\": true }] } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `oxlint --fix` (or eslint --fix) in pre-commit — duplicate imports merge automatically","Configure IDE auto-import to merge into existing statements instead of appending new ones","Decide the considerQueryString stance once, matching your bundler's loader usage"],"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"}