oxc-project/oxc · warning · OxcDiagnostic

Exporting 'default' is restricted.

Error message

Exporting 'default' is restricted.

What it means

The `Direct` branch of `no-restricted-exports`. It fires when the config sets `restrictedDefaultExports.default` and the module contains a direct default export (`export default ...`). Part of enforcing named-export-only codebases.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_restricted_exports.rs:47

    Named,
    DefaultFrom,
    NamedFrom,
    NamespaceFrom,
}

fn no_restricted_default_exports_diagnostic(
    span: Span,
    export_type: DefaultExportType,
) -> OxcDiagnostic {
    let warn = match export_type {
        DefaultExportType::DefaultFrom => "Reexporting 'default' export is restricted.",
        DefaultExportType::Direct => "Exporting 'default' is restricted.",
        DefaultExportType::Named => "Exporting named value as default is restricted.",
        DefaultExportType::NamedFrom => "Reexporting named export as default is restricted.",
        DefaultExportType::NamespaceFrom => "Reexporting namespace as default is restricted.",
    };

    OxcDiagnostic::warn(warn).with_help("Use named export instead.").with_label(span)
}

fn no_restricted_named_exports_diagnostic(span: Span, name: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("'{name}' is restricted from being used as an exported name."))
        .with_help("Rename this export.")
        .with_label(span)
}

#[derive(Debug, Default, Clone, Deserialize)]
pub struct NoRestrictedExports(Box<NoRestrictedExportsConfig>);

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoRestrictedExportsConfig {
    /// An array of strings, where each string is a name to be restricted.
    ///
    /// Example of **incorrect** code for `"restrictedNamedExports": ["foo"]`:
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Convert to a named declaration: `export const Foo = ...;` / `export function foo() {}`.
  2. Update internal consumers to use the named import.
  3. If intentional, drop the `default` key from `restrictedDefaultExports` or disable the rule.

Example fix

// before
export default function run() {}

// after
export function run() {}
Defensive patterns

Strategy: validation

Validate before calling

// Cheap file-level guard for a named-exports-only convention
const src = require('node:fs').readFileSync(file, 'utf8');
if (/^export\s+default\b/m.test(src)) {
  console.error(`${file}: default exports are not allowed`);
  process.exitCode = 1;
}

Prevention

When it happens

Trigger: `"no-restricted-exports": ["error", { "restrictedDefaultExports": { "default": true } }]` combined with any of `export default function foo() {}`, `export default 42;`, `export default class C {}`.

Common situations: Shared library conventions (Airbnb-style) that ban default exports; migrating a codebase to named exports and enforcing it in CI.

Related errors


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