Skip to content

[Bug]: CJS default import emits __toESM(mod, 1) in .ts files but __toESM(mod) in .tsx files #9690

@romain-trotard

Description

@romain-trotard

Reproduction link or steps

Reproduction link: https://github.com/romain-trotard/rolldownCjsTsTsxRepro

  • npm install
  • npm build

See lib/from-ts.js and lib/from-tsx.js files

What is expected?

I would expect both cjs generated files to be the same, with :

let mock_cjs = require("mock-cjs");
mock_cjs = require_chunk.__toESM(mock_cjs);

What is actually happening?

But currently only the cjs generated file for tsx has:

let mock_cjs = require("mock-cjs");
mock_cjs = require_chunk.__toESM(mock_cjs);

node lib/from-tsx.cjs works

The cjs generated file for the ts file contains:

let mock_cjs = require("mock-cjs");
mock_cjs = require_chunk.__toESM(mock_cjs, 1);

which causes mock_cjs.default.div to be undefined in this case

node lib/from-ts.cjs fails

System Info

System:
    OS: macOS 26.5.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 545.19 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 26.3.0 - /Users/romain.trotard/.volta/tools/image/node/26.3.0/bin/node
    Yarn: 1.19.0 - /Users/romain.trotard/.volta/tools/image/yarn/1.19.0/bin/yarn
    npm: 11.16.0 - /Users/romain.trotard/.volta/tools/image/node/26.3.0/bin/npm
    pnpm: 10.12.4 - /Users/romain.trotard/.volta/bin/pnpm
    bun: 1.3.3 - /Users/romain.trotard/.bun/bin/bun
  Browsers:
    Chrome: 148.0.7778.216
    Firefox: 148.0
    Safari: 26.5
  npmPackages:
    rolldown: ^1.1.0 => 1.1.0

Any additional comments?

I found this issue when working with styled-components library.

Metadata

Metadata

Labels

No labels
No labels

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions