oxc-project/oxc · warning
Replace default import with named import.
Error message
Replace default import with named import.
What it means
Diagnostic from the oxlint rule import/no-named-default (style category). It fires when the default export is imported through named-import syntax: `import { default as foo } from './foo.js'` (including string form `import { "default" as bar }`). The dedicated default-import syntax exists to express this directly — `import foo from './foo.js'` — and using the long form obscures which binding is the default. Value-kind specifiers are checked; an inline `type` modifier (`import { type default as Foo }`) is skipped.
Source
Thrown at crates/oxc_linter/src/rules/import/no_named_default.rs:13
use oxc_ast::{
AstKind,
ast::{ImportDeclarationSpecifier, ImportOrExportKind},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::AstNode;
use oxc_span::{GetSpan, Span};
use crate::{context::LintContext, rule::Rule};
fn no_named_default_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Replace default import with named import.")
.with_help("Forbid named default exports.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoNamedDefault;
declare_oxc_lint!(
/// ### What it does
///
/// Reports use of a default export as a locally named import.
///
/// ### Why is this bad?
///
/// Rationale: the syntax exists to import default exports expressively, let's use it.
///
/// ### Examples
///View on GitHub (pinned to e1e7af627c)
Solutions
- Rewrite to default-import syntax: `import foo from './foo.js'`, combining with named imports as `import foo, { bar } from './foo.js'`
- Configure your IDE/auto-import to prefer default-import syntax for default exports
- If the alias is deliberate documentation, add a disable comment for that line
Example fix
// before
import { default as foo, bar } from './foo.js';
// after
import foo, { bar } from './foo.js'; Defensive patterns
Strategy: validation
Validate before calling
// rg -n "import\\s*\\{[^}]*\\bdefault\\b[^}]*\\}\\s*from" src
// .oxlintrc.json: { "rules": { "import/no-named-default": "warn" } } Prevention
- Use dedicated default-import syntax (`import X from`) in hand-written code
- Configure auto-import tooling to emit default syntax for default exports
- During CJS→ESM migration, translate `require('./m').default` to `import X from './m'`, not `{ default as X }`
When it happens
Trigger: Any ImportSpecifier whose imported name is `default` with value import kind — crates/oxc_linter/src/rules/import/no_named_default.rs:63 reports the imported-name span. Also fires inside `import type { default as Quill } from 'quill'` statements used as values. Common producers: codemods, Replit-style auto-imports, and TypeScript code written before defaults were well understood.
Common situations: Auto-import tooling choosing `{ default as X }` when a named export with the wanted name also exists; codebases migrating from CommonJS where `require('./mod').default` was translated literally; copy-pasted snippets from older docs.
Related errors
- Assign instance to a variable before exporting as module def
- Assign array to a variable before exporting as module defaul
- Assign literal to a variable before exporting as module defa
- Expected '{curr_kind}' syntax before '{prev_kind}' syntax.
- Imports should be sorted alphabetically.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/18e410927408b0da.
Report an issue: GitHub.