Design Patterns · Middle · Question 27 of 75

How can barrel files (index.ts re-exporting everything) do harm?

Explanation

Importing one function from a large barrel can force the bundler and test runner to parse the whole module graph, and mutual re-exports easily form cycles. Fixes: narrow public APIs, direct imports within a module, optimizePackageImports in Next.js.

Further reading

Problem with a question

Design Patterns · Middle · question 27

Test yourself

Take the Design Patterns · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz