{"record":{"id":"ff4a167289003d28","repo":"oxc-project/oxc","slug":"module-name-import-is-duplicated","errorCode":null,"errorMessage":"'{module_name}' import is duplicated","messagePattern":"'(.+?)' import is duplicated","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs","lineNumber":21,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_str::CompactStr;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    context::LintContext,\n    module_record::{ExportImportName, ImportImportName},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_duplicate_imports_diagnostic(\n    module_name: &str,\n    span: Span,\n    previous_span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{module_name}' import is duplicated\"))\n        .with_help(\"Merge the duplicated import into a single import statement\")\n        .with_labels([\n            span.label(\"This import is duplicated\"),\n            previous_span.label(\"Can be merged with this import\"),\n        ])\n}\n\nfn no_duplicate_exports_diagnostic(\n    module_name: &str,\n    span: Span,\n    previous_span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{module_name}' export is duplicated\"))\n        .with_help(\"Merge the duplicated exports into a single export statement\")\n        .with_labels([\n            span.label(\"This export is duplicated\"),\n            previous_span.label(\"Can be merged with this\"),\n        ])","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs#L3-L39","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Merge the two statements into one: `import { a, b } from './util';`.","Run the editor command 'organize imports', which merges duplicates.","Align path aliases so one module has exactly one spelling in the file.","Suppress with `// oxlint-disable-next-line no-duplicate-imports` when a merge would break a loader."],"exampleFix":"// before\nimport { read } from './fs.js';\nimport { write } from './fs.js';\n\n// after\nimport { read, write } from './fs.js';","handlingStrategy":"validation","validationCode":"// collect import sources and find repeats\nconst srcs = [...src.matchAll(/import[\\s\\S]*?from\\s+['\"]([^'\"]+)['\"]/g)].map(m => m[1]);\nconst dup = srcs.filter((s, i) => srcs.indexOf(s) !== i);\nif (dup.length) throw new Error('duplicate imports: ' + [...new Set(dup)].join(', '));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Turn on 'organize imports on save' in the editor.","Keep one import block at the top of each file.","Use one path alias per module across the project."],"tags":["javascript","eslint","lint","imports","modules"],"backgroundTag":"lint-duplicate-import","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"}