Skip to content

CJS/ESM conditional exports not deduplicated #8492

@leaysgur

Description

@leaysgur

When a package provides conditional exports (.mjs for ESM / .(c)js for CJS), and consumers import the same subpath via both ESM import() and CJS require(), rolldown seems to bundle both variants as separate module graph nodes instead of deduplicating them.

This causes:

  • Duplicated module code in the output (increased bundle size)
  • Broken module identity (two separate instances of the same logical module)
  • In complex chunk graphs (e.g., tsdown with multiple entries), broken __esmMin init wrappers → TypeError: init_xxx is not a function

I found it while working on oxc-project/oxc#19807.

The reproduction steps and more details are here.
👉🏻 https://github.com/leaysgur/rolldown-esm-cjs-dedupe-repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions