oxc-project/oxc · warning · OxcDiagnostic
Reexporting named export as default is restricted.
Error message
Reexporting named export as default is restricted.
What it means
The `NamedFrom` branch of `no-restricted-exports`. It fires when the config sets `restrictedDefaultExports.namedFrom` and the module re-exports a named import of another module as default: `export { foo as default } from 'mod';`.
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
- Keep the re-export named: `export { utils } from './utils';`.
- If legacy consumers need a default, have them import the named export instead.
- Drop `namedFrom` from the config when this pattern is acceptable.
Example fix
// before
export { utils as default } from './utils';
// after
export { utils } from './utils'; Defensive patterns
Strategy: validation
Validate before calling
// Detect `export { x as default } from '...'`
const src = require('node:fs').readFileSync(file, 'utf8');
if (/export\s*\{[^}]*\bas\s+default\s*\}\s*from\s*['"]/.test(src)) {
console.error('re-exporting a named binding as default is banned');
process.exitCode = 1;
} Prevention
- Keep re-exports symmetric: named in, named out.
- Enforce with `restrictedDefaultExports.namedFrom` rather than ad-hoc review.
When it happens
Trigger: `restrictedDefaultExports: { "namedFrom": true }` in .oxlintrc plus `export { utils as default } from './utils';`.
Common situations: Facade modules that promote one named export to default for legacy consumers; enforcing named-export-only policy across re-exports.
Related errors
- Reexporting 'default' export is restricted.
- Exporting 'default' is restricted.
- Exporting named value 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/787d7c0fe464a9f7.
Report an issue: GitHub.