{"record":{"id":"60593d886d6bc6d6","repo":"oxc-project/oxc","slug":"module-name-export-is-duplicated","errorCode":null,"errorMessage":"'{module_name}' export is duplicated","messagePattern":"'(.+?)' export is duplicated","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs","lineNumber":34,"sourceCode":"fn 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        ])\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoDuplicateImports {\n    /// When `true` this rule will also look at exports to see if there is both a re-export of a\n    /// module as in `export ... from 'module'` and also a standard import statement for the same\n    /// module. This would count as a rule violation because there are in a sense two statements\n    /// importing from the same module.\n    ///\n    /// Examples of **incorrect** code when `includeExports` is set to `true`:\n    /// ```js\n    /// import { merge } from 'module';","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs#L16-L52","documentation":"This diagnostic comes from the same `no_duplicate_imports` rule, from its export branch. It fires only when the option `includeExports` is set to `true`. It reports a re-export from a module (`export ... from 'm'`) when the file also imports from that module, or a duplicate export of the same name. The report labels the export and the earlier statement it collides with.","triggerScenarios":"The rule config sets `includeExports: true`, and the file contains both `import { a } from './m';` and `export { b } from './m';`. The diagnostic names the module and points at both spans.","commonSituations":"A barrel file (index.js) imports helpers from a module and also re-exports parts of it. An export line is added next to an import of the same module during a refactor.","solutions":["Keep one statement per module: import what the file uses, and re-export from a separate barrel.","Rewrite as `import { helper, formatDate } from './utils.js'; export { formatDate };` so only the import touches the module.","Set `includeExports` back to `false` when the overlap is intended.","Suppress one line with `// oxlint-disable-next-line no-duplicate-imports`."],"exampleFix":"// before\nimport { helper } from './utils.js';\nexport { formatDate } from './utils.js';\n\n// after\nimport { helper, formatDate } from './utils.js';\nexport { formatDate };","handlingStrategy":"validation","validationCode":"// report import + re-export overlap for the same module\nconst imports = new Set([...src.matchAll(/import[\\s\\S]*?from ['\"]([^'\"]+)['\"]/g)].map(m => m[1]));\nfor (const m of src.matchAll(/export\\s*\\{[^}]*\\}\\s*from ['\"]([^'\"]+)['\"]/g)) {\n  if (imports.has(m[1])) throw new Error('import and export share module ' + m[1]);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep barrel files re-export-only; do the work in separate modules.","Enable `includeExports` only when you want the strict check.","Run 'organize imports' before each commit."],"tags":["javascript","eslint","lint","exports","modules"],"backgroundTag":"lint-duplicate-export","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}