v7 and v8 are not tree-shakable

Author: samuelstroscheinCreated Feb 3, 2025Updated Feb 6, 2025

Problem

Tree-shaking is not working with v7 and above because the ESM build has been removed.

I am the author of Paraglide JS. Tree-shaking is a key differentiator. For locale detection reasons, I'd like to use path-to-regexp on the client. The lack of tree-shaking (which would increase the runtime size from <1kb to >4kb) and ESM problems like #346 prevent me from adopting path-to-regexp.

Using URLPattern instead of path-to-regexp is not possible because a reverse compile function is missing https://github.com/whatwg/urlpattern/issues/73.

Reproduction

  1. Open https://bundlejs.com/?q=path-to-regexp%407&treeshake=%5B%7B+compile+%6D%5D
  2. Press build
  3. Repeat with v7 and v8

To inspect the bundle, disable minify: true in the settings. V6 only contains functions used in compile, while >V7 bundles everything.

Proposal

Re-introduce dual CJS + ESM build, or say goodbye to CJS altogether, now that Node supports native require(esm).