Skip to content

Tree shaking differs between splitting and no splitting #3704

Description

@taylorzane

Repro: https://github.com/taylorzane/esbuild-elkjs-bundle (includes bundle output and metafiles)

When using the following library (@unovis/ts) inside of an esbuild bundle, a number of modules that are imported by various components are not properly tree-shaken when code splitting is enabled. When code splitting is disabled, the modules are correctly discarded.

As far as I can tell this is primarily caused by the bare import in @unovis/ts/index.js that leads to the (one of many) following chain:

@unovis/ts/index.js => import-statement => @unovis/ts/components.js 
@unovis/ts/components.js => import-statement => @unovis/ts/components/graph/index.js
@unovis/ts/components/graph/index.js => import-statement => @unovis/ts/components/graph/modules/layout.js
@unovis/ts/components/graph/modules/layout.js => dynamic-import => elkjs/lib/elk.bundled.js

It's not immediately clear whether the underlying problem is with esbuild or the library, but the discrepancy between splitting/no splitting is odd.

esbuild: 0.20.2
@unovis/ts: 1.3.5

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions