{"record":{"id":"78c16ad3863a6b29","repo":"oxc-project/oxc","slug":"barrel-file-detected-total-modules-are-loaded-w","errorCode":null,"errorMessage":"Barrel file detected, {total} modules are loaded which exceeds the threshold of {threshold}.","messagePattern":"Barrel file detected, (.+?) modules are loaded which exceeds the threshold of (.+?)\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/oxc/no_barrel_file.rs","lineNumber":14,"sourceCode":"use crate::{\n    ModuleRecord,\n    context::LintContext,\n    module_graph_visitor::{ModuleGraphVisitorBuilder, VisitFoldWhile},\n    rule::{DefaultRuleConfig, Rule},\n};\nuse oxc_diagnostics::{LabeledSpan, OxcDiagnostic};\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nfn no_barrel_file(total: u32, threshold: u32, labels: Vec<LabeledSpan>) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"Barrel file detected, {total} modules are loaded which exceeds the threshold of {threshold}.\",\n    ))\n    .with_help(format!(\"Consider importing directly from the specific modules instead of using `export *` or `import *`.\\nLoading {total} modules may be slow for runtimes and bundlers.\"))\n    .with_note(\"See: https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7\")\n    .with_labels(labels)\n}\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoBarrelFile {\n    /// The maximum number of modules that can be re-exported via `export *`\n    /// before the rule is triggered.\n    threshold: u32,\n}\n\nimpl Default for NoBarrelFile {\n    fn default() -> Self {\n        Self { threshold: 100 }","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/oxc/no_barrel_file.rs#L1-L32","documentation":"Oxlint rule `oxc/no_barrel_file` uses the module graph to count how many modules a file pulls in via `export *` / `import *` re-exports. When that count exceeds the configured threshold, the file is flagged as a barrel: importing anything from it forces runtimes and bundlers to load and parse the entire re-exported subtree, slowing cold starts and builds.","triggerScenarios":"An `index.ts`/`index.js` containing many `export * from './x'` statements (or `import * as ns from './x'; export { ns }` equivalents) whose transitively reachable module count, resolved through the module graph, is greater than the rule's `maximumModules`-style threshold option.","commonSituations":"Component/utility libraries exporting everything from one index; monorepo package barrels that transitively re-export hundreds of modules; slow dev-server or CI cold starts traced to barrel imports.","solutions":["Import directly from the specific feature modules at call sites instead of the barrel","Replace `export *` with explicit named re-exports limited to the public API surface","Raise the threshold in `.oxlintrc.json` for known-good barrels, or disable the rule via `overrides` for that one file","Split the barrel into smaller topical entry points"],"exampleFix":"// before (src/index.ts)\nexport * from './button';\nexport * from './input';\n// ... 120 more modules\n\n// after (call sites import directly)\nimport { Button } from './ui/button';\nimport { Input } from './ui/input';","handlingStrategy":"fallback","validationCode":"// quick pre-check before adding a new export * to a barrel\ncount=$(rg -c \"^export \\*\" src/index.ts || echo 0)\necho \"barrel re-exports: $count\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to importing from feature modules; treat barrels as public API entry points only","Prefer explicit named re-exports over export * so the reachable module set stays small and greppable","Watch bundler dev-server cold-start times; a jump usually means a barrel crossed the threshold"],"tags":["oxlint","barrel-file","performance","bundling","module-graph"],"backgroundTag":"barrel-file-bundle-bloat","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"}