{"record":{"id":"9dc4948de239a6f3","repo":"oxc-project/oxc","slug":"prefer-default-export-to-be-present-on-every-file","errorCode":null,"errorMessage":"Prefer default export to be present on every file that has export.","messagePattern":"Prefer default export to be present on every file that has export\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/prefer_default_export.rs","lineNumber":19,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\nuse serde_json::Value;\n\nuse crate::{\n    context::LintContext,\n    module_record::ExportEntry,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn prefer_default_export_diagnostic(span: Span, target: Target) -> OxcDiagnostic {\n    let msg = if target == Target::Single {\n        \"Prefer default export on a file with single export.\"\n    } else {\n        \"Prefer default export to be present on every file that has export.\"\n    };\n    OxcDiagnostic::warn(msg).with_help(\"Prefer a default export\").with_label(span)\n}\n\n#[derive(Debug, Default, PartialEq, Clone, Copy, Deserialize, Serialize, JsonSchema)]\n#[serde(rename_all = \"kebab-case\")]\nenum Target {\n    /// Prefer default export when there is only one export in the module.\n    #[default]\n    Single,\n    /// Prefer default export in any module that has exports.\n    Any,\n}\n\n#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct PreferDefaultExport {\n    /// Configuration option to specify the target type for preferring default exports.\n    target: Target,","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/prefer_default_export.rs#L1-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (utils.ts)\nexport function clamp(n: number, min: number, max: number) { /* ... */ }\n\n// after (utils.ts)\nexport function clamp(n: number, min: number, max: number) { /* ... */ }\nexport default { clamp };","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["lint","import","export","style","esm","oxlint"],"backgroundTag":"module-export-style","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}