Skip to content

https://dev.to/tassiofront/barrel-files-and-why-you-should-stop-using-them-now-bc4

Yes, I use side effects free packages every day. Third party and my own packages. Three.js and ramda on npm are both side effects free to name a few popular ones.

For tests I definitely agree you shouldn’t be importing via barrel files. A unit test should depend on only its unit, regardless of tree shaking capabilities. I almost exclusively only use barrel files as a definition for what my packages export. Everything else I split up into separate modules so that my codebase can have a proper dependency tree.

I think your article demonstrates important concerns. If one wants a no-build architecture, then being aware of how modules work is very useful, and avoiding barrel files becomes more important. But if one has a build system already then you do have the option to tree shake. I don’t think it’s wise to pass judgement on a whole and say it’s either right or wrong. There are upsides and downsides, and everything depends on context of the team and project.