Skip to content

[Bug]: build with output.inlineDynamicImports doesn't treeshake properly and produces invalid ESM code #6935

@BlankParticle

Description

@BlankParticle

Reproduction link or steps

repro: https://github.com/BlankParticle/rolldown-inlineDynamicImports-reprod

build the code with pnpm build, the output code in dist/index.js (//#region node_modules/.pnpm/[email protected]/node_modules/undici/index.js) will have module.exports.[module] code in global scope without the __CommonJS wrapper, which is invalid ESM code and causes node to crash

ideally undici code shouldn't even be in the bundle as it was a dynamic import in a function that was treeshaken out, so it has no use even with import side effects.

Image

What is expected?

Ideally Undici code will be entirely treeshaken out
right now, it shouldnt produce invalid ESM code

What is actually happening?

Undici code is still in the bundle and invalid code is produced in build

System Info

System:
    OS: macOS 26.0.1
    CPU: (16) arm64 Apple M4 Max
    Memory: 5.43 GB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.3.0 - /Users/blank/.local/state/fnm_multishells/1025_1762850271844/bin/node
    npm: 11.4.2 - /Users/blank/.local/state/fnm_multishells/1025_1762850271844/bin/npm
    pnpm: 10.20.0 - /Users/blank/.local/state/fnm_multishells/1025_1762850271844/bin/pnpm
    bun: 1.3.0 - /Users/blank/.bun/bin/bun
  Browsers:
    Chrome: 142.0.7444.135
    Safari: 26.0.1
  npmPackages:
    rolldown: 1.0.0-beta.49 => 1.0.0-beta.49

Any additional comments?

No response

Metadata

Metadata

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions