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 value

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Convert the default export to a named export and update every importer: `import Foo from './foo'` → `import { Foo } from './foo'`
  2. 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)
  3. 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

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


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/18057a30154e1c7a. Report an issue: GitHub.