The hidden cost of barrel files
January 14, 2026
I used to love barrel files. Those index.ts files that re-export everything from a folder, so you get one tidy import instead of five. No digging through the filesystem to find the right path. What's not to like? Turns out plenty, once a codebase grows past "small."
The problem is bundlers have to parse the whole barrel to figure out what's actually being used. Tree-shaking helps, but not as much as people assume. Circular dependencies sneak in quietly, import chains get deep, and modules start evaluating way earlier than they need to. I watched a team's build times creep up for weeks before anyone connected it to the barrels they'd standardized on.
On one dashboard project I was debugging, I opened the Network tab on a cold load out of curiosity and counted over 1,600 module requests. Sixteen hundred. Not all of that was barrels, but after I went through and switched the feature folders to direct imports, keeping barrels only around the design system, it settled down to somewhere between 900 and 1,100 depending on the route. Vite's build got a few seconds faster too. Nobody on the team really noticed the change, which is honestly how you know infrastructure work went well.
My rule now: direct imports for anything performance-sensitive, barrels only for things that are genuinely public, a library's surface, a shared design system. Not every folder that happens to have more than one file in it.