oxc-project/oxc · warning · OxcDiagnostic
'{name}' is restricted from being used as an exported name.
Error message
'{name}' is restricted from being used as an exported name. What it means
The named-export branch of `no-restricted-exports`. It fires for every exported name listed under `restrictedNamedExports`, regardless of how the export is written (declaration, `export { }` list, or `as` alias). The help text says to rename the export.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_restricted_exports.rs:51
}
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"]`:
///
/// ```ts
/// export const foo = 1;
/// ```
///View on GitHub (pinned to e1e7af627c)
Solutions
- Rename the export to an allowed name and update importers.
- If the binding should stay internal, remove the `export` keyword.
- Remove the name from `restrictedNamedExports` if the restriction is outdated.
Example fix
// before
export function fetch(url) { /* ... */ }
// after
export function request(url) { /* ... */ } Defensive patterns
Strategy: validation
Validate before calling
// Verify a module's exported names against a public-API allowlist
const exportedNames = new Set(
[...src.matchAll(/export\s+(?:const|let|var|function|class)\s+([A-Za-z_$][\w$]*)/g)].map(m => m[1])
.concat([...src.matchAll(/export\s*\{([^}]*)\}/g)].flatMap(m =>
m[1].split(',').map(s => s.trim().split(/\s+as\s+/).pop())
))
);
const ALLOWED = new Set(['request', 'configure']);
for (const name of exportedNames) if (!ALLOWED.has(name)) console.error(`unexpected export: ${name}`); Prevention
- Maintain `restrictedNamedExports` alongside the library's public API docs so both stay in sync.
- Review new `export` keywords in PR diffs for entry-point files.
- Consider API extractor tools (ts-api-extractor) to freeze the exported surface.
When it happens
Trigger: `"restrictedNamedExports": ["fetch", "dispose"]` in .oxlintrc combined with `export function fetch() {}`, `const a = 1; export { a as dispose };`, or `export { cloneNode } from './dom';` when the name is on the list.
Common situations: Public API allowlists that freeze a library's exported surface; preventing exports of internal helpers; banning names that collide with DOM/Node built-ins in public entry points.
Related errors
- Reexporting 'default' export is restricted.
- Exporting 'default' is restricted.
- Exporting named value as default is restricted.
- Reexporting named export as default is restricted.
- Reexporting namespace as default is restricted.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/98d5ead6b68c06d6.
Report an issue: GitHub.