oxc-project/oxc · warning
Prefer default export to be present on every file that has e
Error message
Prefer default export to be present on every file that has export.
What it means
This is oxlint's 'import/prefer-default-export' diagnostic in its non-default "any" target mode. With { "target": "any" }, the rule demands a default export from every module that has any exports at all, so a file with only named exports is reported. The message and help text point you to adding a default export.
Source
Thrown at crates/oxc_linter/src/rules/import/prefer_default_export.rs:19
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::{
context::LintContext,
module_record::ExportEntry,
rule::{DefaultRuleConfig, Rule},
};
fn prefer_default_export_diagnostic(span: Span, target: Target) -> OxcDiagnostic {
let msg = if target == Target::Single {
"Prefer default export on a file with single export."
} else {
"Prefer default export to be present on every file that has export."
};
OxcDiagnostic::warn(msg).with_help("Prefer a default export").with_label(span)
}
#[derive(Debug, Default, PartialEq, Clone, Copy, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
enum Target {
/// Prefer default export when there is only one export in the module.
#[default]
Single,
/// Prefer default export in any module that has exports.
Any,
}
#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct PreferDefaultExport {
/// Configuration option to specify the target type for preferring default exports.
target: Target,View on GitHub (pinned to e1e7af627c)
Solutions
- Add a default export to the module that exposes its primary entity (e.g. export default mainComponent alongside named helpers).
- If the file is a barrel (index.ts re-exports), exclude it from the rule via overrides in .oxlintrc.json.
- If your team actually prefers named exports, change the config back to the default target "single" or disable the rule.
- Inline-suppress deliberate exceptions with // oxlint-disable-next-line import/prefer-default-export.
Example fix
// before (utils.ts)
export function clamp(n: number, min: number, max: number) { /* ... */ }
// after (utils.ts)
export function clamp(n: number, min: number, max: number) { /* ... */ }
export default { clamp }; Defensive patterns
Strategy: validation
Prevention
- Only set target "any" when the codebase standardizes on default exports.
- Exclude barrel/index files from import/prefer-default-export via config overrides.
- Add a default export when creating any new module with exports under this policy.
When it happens
Trigger: Configure the rule as "import/prefer-default-export": ["error", { "target": "any" }] and lint a module that has at least one export entry but no default export entry. The diagnostic's span covers the offending export.
Common situations: Teams that standardize on default exports (many Angular or older React codebases) enable target "any" during lint migrations and get flooded with reports on barrel files and pure named-export utility modules. Accidentally configuring target "any" when the single mode was intended is also common.
Related errors
- Prefer default export on a file with single export.
- Exporting mutable '{kind_str}' binding, use 'const' instead.
- Tried to get an allocator from an empty `FixedSizeAllocatorP
- Prefer using inline type specifiers instead of a top-level t
- Prefer using a top-level type-only import instead of inline
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/9dc4948de239a6f3.
Report an issue: GitHub.