oxc/no-barrel-file
Disallow files that load too many modules through export *
A barrel file re-exports other files with export *. Importing one name from it loads every file behind it, and every file those import. In a large project, that slows down startup, tests, and bundling for code that's never used.
Each export * or export * as name counts as one module, plus every module the re-exported file imports, directly or through other files. The file is reported when the total is more than threshold.
With an oxlint config, other files are only read if the import plugin is on. Without it, only the export * lines count.
Configure#
Off by default. To turn it on:
[lint.rules]
"oxc/no-barrel-file" = "error" # or "warn"Every option, set to its default:
[lint.rules]
"oxc/no-barrel-file" = ["error", {
threshold = 100,
}]Examples#
With threshold set to 3, this index.js is reported. Each export * loads two modules, which makes four:
export const db = new Map();import { db } from "./db.js";
export const findUser = id => db.get(`user:${id}`);import { db } from "./db.js";
export const findOrder = id => db.get(`order:${id}`);{ "threshold": 3 }1 problemexport * from "./users.js"Barrel file detected, 4 modules are loaded which exceeds the threshold of 3.;
export * from "./orders.js";db.js counts twice, once for each export * that reaches it.
Exports that name what they export are never counted:
{ "threshold": 0 }No problemsexport { findUser } from "./users.js";
export { findOrder } from "./orders.js";Options#
| Option | Default | What it does |
|---|---|---|
threshold | 100 | The largest number of modules a file can load through export *. |
[lint.rules]
"oxc/no-barrel-file" = ["error", { threshold = 20 }]