oxc-project/oxc · warning · OxcDiagnostic
Exporting named value as default is restricted.
Error message
Exporting named value as default is restricted.
What it means
The `Named` branch of `no-restricted-exports`. It fires when the config sets `restrictedDefaultExports.named` and the module aliases a local binding to the default export name: `export { foo as default };`.
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
- Export the binding under its own name: `export { foo };`.
- Alternatively declare it named from the start: `export const foo = 1;`.
- Remove `named` from `restrictedDefaultExports` if this shape is allowed.
Example fix
// before
const foo = 1;
export { foo as default };
// after
export const foo = 1; Defensive patterns
Strategy: validation
Validate before calling
// Detect `export { x as default };` aliases
const src = require('node:fs').readFileSync(file, 'utf8');
if (/export\s*\{[^}]*\bas\s+default\s*\}/.test(src)) {
console.error('aliasing a named binding to default is banned');
process.exitCode = 1;
} Prevention
- Declare exports as `export const/function` directly instead of aliasing at the bottom of the file.
- Enable `restrictedDefaultExports.named` so tooling, not memory, enforces the rule.
When it happens
Trigger: `restrictedDefaultExports: { "named": true }` in .oxlintrc plus code like `const foo = 1; export { foo as default };`.
Common situations: Codemods that mechanically rename default exports to `as default` aliases; refactoring halfway between default and named export styles.
Related errors
- Reexporting 'default' export is restricted.
- Exporting 'default' is restricted.
- Reexporting named export as default is restricted.
- Reexporting namespace as default is restricted.
- '{name}' is restricted from being used as an exported name.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/8f1abc5bbec0b326.
Report an issue: GitHub.