oxc-project/oxc · warning · OxcDiagnostic
Prefer named exports
Error message
Prefer named exports
What it means
Diagnostic from the oxlint rule import/no-default-export (restriction category). It fires on every `export default ...` declaration, enforcing a named-exports-only module style. Named exports force consistent names between declaration and import sites, improve refactorings/auto-imports, and avoid the ambiguity of defaults; teams that adopt this policy turn the rule on explicitly.
Source
Thrown at crates/oxc_linter/src/rules/import/no_default_export.rs:8
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{context::LintContext, rule::Rule};
fn no_default_export_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer named exports")
.with_help("Replace this default export with a named export.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoDefaultExport;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow modules from having default exports.
///
/// This can help your editor provide better auto-import functionality, as named exports
/// offer more explicit and predictable imports compared to default exports.
///
/// ### Why is this bad?
///
/// Default exports can lead to confusion, as the name of the imported valueView on GitHub (pinned to e1e7af627c)
Solutions
- Convert the default export to a named export and update every importer: `import Foo from './foo'` → `import { Foo } from './foo'`
- Keep default exports and turn the rule off ("import/no-default-export": "off") if they are part of your API (e.g. Vue SFC default exports, CSS modules, Next.js pages)
- Scope the rule to directories where the policy applies using config overrides
Example fix
// before const foo = "bar"; export default foo; // after export const foo = "bar";
Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json — scope the policy instead of fighting it per-file
{ "rules": { "import/no-default-export": "off" },
"overrides": [{ "files": ["src/utils/**"], "rules": { "import/no-default-export": "warn" } }] } Prevention
- Decide the named-vs-default policy per project area and encode it in overrides
- Use explicit `import { X }` in new code — it survives renames better than defaults
- Watch for framework constraints (Vue SFC, Next.js pages) that require defaults and exclude those globs
When it happens
Trigger: Any ExportDefaultDeclaration (`export default foo`, `export default function bar() {}`, etc.) in a file where the rule is enabled. Constructed by no_default_export_diagnostic at crates/oxc_linter/src/rules/import/no_default_export.rs:8.
Common situations: Teams standardizing on named exports (common in large React/TypeScript codebases and some style guides that forbid defaults); codemods converting a library's public surface to named exports; accidental enabling of the whole restriction category.
Related errors
- Module {export_name:?} has named export {module_name:?}
- {module_name:?} also has a named export {export_name:?}
- Named exports are not allowed.
- Assign instance to a variable before exporting as module def
- Assign array to a variable before exporting as module defaul
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/18057a30154e1c7a.
Report an issue: GitHub.