{"record":{"id":"f0146ae8a8a0a462","repo":"oxc-project/oxc","slug":"module-name-also-has-a-named-export-export-na","errorCode":null,"errorMessage":"{module_name:?} also has a named export {export_name:?}","messagePattern":"(.+?) also has a named export (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/import/no_named_as_default_member.rs","lineNumber":19,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{BindingPattern, Expression, IdentifierReference},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::SymbolId;\nuse oxc_span::{GetSpan, Span};\nuse rustc_hash::FxHashMap;\n\nuse crate::{context::LintContext, module_record::ImportImportName, rule::Rule};\n\nfn no_named_as_default_member_diagnostic(\n    span: Span,\n    module_name: &str,\n    export_name: &str,\n    suggested_module_name: &str,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"{module_name:?} also has a named export {export_name:?}\"))\n        .with_help(format!(\"Check if you meant to write `import {{ {export_name} }} from {suggested_module_name:?}`\"))\n        .with_label(span)\n}\n\n// <https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-named-as-default-member.md>\n#[derive(Debug, Default, Clone)]\npub struct NoNamedAsDefaultMember;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Reports the use of an exported name (named export) as a property on the\n    /// default export. This occurs when trying to access a named export through\n    /// the default export, which is incorrect.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Accessing a named export via the default export is incorrect and will not","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/no_named_as_default_member.rs#L1-L37","documentation":"Diagnostic from the oxlint rule import/no-named-as-default-member (suspicious category). It fires when a property is read off a default import and that property is a named export of the same module: given bar.js exports `function bar()` and a default, writing `import foo from './bar'; foo.bar` yields undefined at runtime — the named export does not live on the default. The help text prints the exact intended import, e.g. `import { bar } from './bar'`. This is one of the few style-adjacent rules that catches a real runtime bug.","triggerScenarios":"A default-import binding (resolved to a root symbol) is the object of a static member expression whose property name is in the remote module's exported_bindings — crates/oxc_linter/src/rules/import/no_named_as_default_member.rs:19 reports the whole `foo.bar` span. Classic case: `import React from './react'; React.Component` or `import Moment from 'moment'; Moment.moment`.","commonSituations":"Libraries that expose both a default object and named exports (moment, axios-style SDKs); copy-paste from docs that used namespace imports; refactors where a named export was newly added and old member access now resolves to undefined.","solutions":["Import the named export directly: `import { bar } from './bar'` (exactly what the help string prints)","If you need both: `import foo, { bar } from './bar'` and use `bar` directly","If the default genuinely has that property AND the module named-exports the same thing, pick one deliberately and delete the ambiguous member access"],"exampleFix":"// bar.js\nexport function bar() { return null }\nexport default () => { return 1 }\n\n// before\nimport foo from './bar';\nconst bar = foo.bar; // undefined at runtime\n\n// after\nimport { bar } from './bar';","handlingStrategy":"validation","validationCode":"// npx oxlint src  (rule is in the default suspicious set)\n// Optional runtime assert during migration:\n// if (typeof foo.bar === 'undefined') throw new Error('foo.bar missing — did you mean import { bar }?');","typeGuard":"// narrows before use when the member genuinely exists on the default\nconst hasBar = (v: unknown): v is { bar: () => unknown } =>\n  typeof v === 'object' && v !== null && 'bar' in v;","tryCatchPattern":null,"preventionTips":["Never read named exports through a default import — import them directly","For libs exposing both (moment-style), pin the import style in the team style guide","Add a smoke test asserting imported members are defined when adopting such a library"],"tags":["lint","oxlint","imports","default-export","named-export","runtime-bug","undefined","suspicious"],"backgroundTag":"named-export-accessed-via-default","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"}