Skip to content

Runtime helpers not properly injected into dynamically imported chunks in CJS format #7655

@shulaoda

Description

@shulaoda

Description

When using dynamic import with CJS output format, the runtime helper functions (like __commonJSMin) are not properly injected into the dynamically imported chunks. Instead, the generated code incorrectly tries to import them from the entry chunk.

Reproduction

REPL: https://repl.rolldown.rs/#eNptUM1KxDAQfpUhl7ZQ4yqKEFlfQfCcS23T3UqSKWmyu1L67s6kXVzQS8j8fH8zi16oWQy+MxcZJ/57oX7rWrRcuhFDLLWQ9w11tahkPBpflq6C/Ru06Ce0Rlo8lE52pm+SjVX1SmgjVAzJLLVg4JU+/1dqh10iqLmwwgR7mHXQHuDU2GQUPD3Wa3001qKC4ozBdkVuLvwIog5obYdnL8lIPxxuhP6Z3CaC+D0amOFjW3sf40BZYIE+oIPiCi+0155TRs5KROoPhI2TzcGPKSpY6aUzsZG5VfMQU8zTvAnQY3ANlUX7NZECwMKZSGk9BmyH3CQ5KmU9kfkHuZO7u08mf34Ryw/rx5ge

// index.js
import("./a.ts").then((m) => console.log(m.default));

// a.ts
module.exports = {
  value: 42,
  hello: 'world',
}

Actual Output

The dynamically imported chunk a-DKX7L-vB.js incorrectly generates:

const require_index = require('./index.js');

var require_a = /* @__PURE__ */ require_index.__commonJSMin(((exports, module) => {
    // ...
}));

The output tries to access __commonJSMin from the entry chunk via require('./index.js').__commonJSMin, which doesn't work because index.js doesn't export the runtime helpers.

Expected Behavior

The runtime helper __commonJSMin should be export.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions