Challenge 1: Tree Shaking the Five-Function Utils Module — Possible Solution ==================================================================== WHAT TREE SHAKING DOES HERE ------------------------------ Per this chapter's own example, utils.js exports five functions (formatDate, formatPrice, slugify, debounce, throttle), but app.js only imports two of them: formatPrice and slugify. Tree shaking analyzes the whole reachable dependency graph (build-tooling1-2) and determines that formatDate, debounce, and throttle are never actually imported by anything reachable from the entry point. Since nothing uses them, the bundler safely removes them (and any dependencies THEY alone would have needed) from the final output entirely — only formatPrice, slugify, and whatever those two specifically depend on end up in the shipped bundle. WHY THIS ONLY WORKS RELIABLY BECAUSE THE IMPORT IS ESM ------------------------------ Per build-tooling1-2's own explanation, ES Modules' import statements are static — required to sit at the top level of a file, with a fixed, literal specifier, never conditional or computed. This means the bundler can determine, with total certainty, by parsing app.js's text alone, that exactly formatPrice and slugify are imported and nothing else — there's no way a hidden runtime condition could later reveal that formatDate is secretly needed after all. If app.js had instead used CommonJS's require() to pull in utils.js, that certainty would disappear: require() calls can be dynamic or conditional (per build-tooling1-2's own dynamic-require example), so a bundler could never be fully sure whether some other, less obvious code path might actually need formatDate, debounce, or throttle at runtime. Removing them in that case would be a genuine risk, not a safe, certain optimization — which is exactly why CommonJS code can't be tree-shaken with the same confidence ESM code can. WHY THIS WORKS AS AN ANSWER ------------------------------ It applies tree shaking to the specific example given (correctly identifying which three functions get removed), and explains the ESM- specific certainty (static, non-conditional imports) that makes the removal provably safe, contrasted against what would go wrong if the same code used CommonJS instead.