oxc-project/oxc · error · OxcDiagnostic
Unexpected default export of anonymous function
Error message
Unexpected default export of anonymous function
What it means
Fires from import/no-anonymous-default-export when a module's default export is a function declaration with no name and the allowAnonymousFunction option is false. The run match arm labels the export declaration span and passes this specific message to the shared diagnostic helper.
Source
Thrown at crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:141
short_description = "Disallow anonymous default exports in modules.",
);
impl Rule for NoAnonymousDefaultExport {
fn from_configuration(value: Value) -> Result<Self, serde_json::error::Error> {
DefaultRuleConfig::<Self>::from_value(value).map(DefaultRuleConfig::into_inner)
}
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let AstKind::ExportDefaultDeclaration(export_decl) = node.kind() else {
return;
};
match &export_decl.declaration {
ExportDefaultDeclarationKind::FunctionDeclaration(func_decl)
if !self.allow_anonymous_function && func_decl.id.is_none() =>
{
ctx.diagnostic(no_anonymous_default_export_diagnostic(
export_decl.span,
"Unexpected default export of anonymous function",
));
}
ExportDefaultDeclarationKind::ClassDeclaration(class_decl)
if !self.allow_anonymous_class && class_decl.id.is_none() =>
{
ctx.diagnostic(no_anonymous_default_export_diagnostic(
export_decl.span,
"Unexpected default export of anonymous class",
));
}
ExportDefaultDeclarationKind::ArrowFunctionExpression(_)
if !self.allow_arrow_function =>
{
ctx.diagnostic(no_anonymous_default_export_diagnostic(
export_decl.span,
"Assign arrow function to a variable before exporting as module default",
));
}View on GitHub (pinned to e1e7af627c)
Solutions
- Name the function before default-exporting it: `export default function myFn() {}`
- Enable `allowAnonymousFunction` if anonymous functions are acceptable
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:141 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/2b6ad0038cdb333b.
Report an issue: GitHub.