Skip to content

fix(rolldown_plugin_esm_external_require): apply conversion to UMD and IIFE outputs#8359

Merged
graphite-app[bot] merged 1 commit intomainfrom
02-17-fix_rolldown_plugin_esm_external_require_apply_conversion_to_umd_and_iife_outputs
Feb 17, 2026
Merged

fix(rolldown_plugin_esm_external_require): apply conversion to UMD and IIFE outputs#8359
graphite-app[bot] merged 1 commit intomainfrom
02-17-fix_rolldown_plugin_esm_external_require_apply_conversion_to_umd_and_iife_outputs

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Feb 17, 2026

require is left as-is for https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for UMD output and IIFE output (REPL UMD, REPL IIFE). That said, there's no way to achieve the on-demand execution semantics of require in AMD and IIFE, and thus it's not possible to achieve that in UMD as well.

This means we cannot add support internally like we do with CJS output and the user has to handle these cases. However, the esmExternalRequirePlugin only did the require -> import conversion for ESM outputs (REPL UMD, REPL IIFE).

This PR changes the esmExternalRequirePlugin to also handle UMD output and IIFE output.

fixes #8349

Copy link
Member Author

sapphi-red commented Feb 17, 2026


How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sapphi-red sapphi-red force-pushed the 02-17-test_rolldown_plugin_esm_external_require_plugin_add_tests branch from 1d46f71 to ca462ab Compare February 17, 2026 06:41
@sapphi-red sapphi-red force-pushed the 02-17-fix_rolldown_plugin_esm_external_require_apply_conversion_to_umd_and_iife_outputs branch from adee2e7 to f13e922 Compare February 17, 2026 06:41
Base automatically changed from 02-17-test_rolldown_plugin_esm_external_require_plugin_add_tests to main February 17, 2026 06:53
@sapphi-red sapphi-red marked this pull request as ready for review February 17, 2026 06:58
Copilot AI review requested due to automatic review settings February 17, 2026 06:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where require() calls for external dependencies were left unchanged in UMD and IIFE output formats, causing browser runtime errors. The fix changes the plugin logic to convert require() calls to ESM imports for all output formats except CJS, since CJS is the only format that natively supports require().

Changes:

  • Modified the format check in lib.rs from !is_esm() to matches!(OutputFormat::Cjs) to enable conversion for UMD and IIFE formats
  • Added comprehensive test coverage for UMD, IIFE, and CJS output formats
  • Added tests for regex pattern matching and Node.js built-in modules

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/rolldown_plugin_esm_external_require/src/lib.rs Changed the condition to apply conversion for ESM, UMD, and IIFE formats, keeping require() only for CJS
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/umd-output/_config.ts Added test verifying UMD output converts require to AMD-style imports
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/umd-output/main.js Test source file with require() call for UMD format
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/iife-output/_config.ts Added test verifying IIFE output converts require to function parameters
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/iife-output/main.js Test source file with require() call for IIFE format
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/cjs-output/_config.ts Added test verifying CJS output keeps require() unchanged
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/cjs-output/main.js Test source file with require() call for CJS format
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/basic/_config.ts Test for basic ESM output conversion
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/basic/main.js Test source file for basic ESM case
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/regex-external/_config.ts Test verifying regex pattern matching works correctly
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/regex-external/main.js Test source file with multiple require() calls matching regex pattern
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/node-builtin/_config.ts Test verifying special handling for Node.js built-in modules
packages/rolldown/tests/fixtures/builtin-plugin/esm-external-require-plugin/node-builtin/main.js Test source file with Node.js built-in module require()

@sapphi-red sapphi-red force-pushed the 02-17-fix_rolldown_plugin_esm_external_require_apply_conversion_to_umd_and_iife_outputs branch from f13e922 to b66de59 Compare February 17, 2026 07:06
@netlify
Copy link

netlify bot commented Feb 17, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit ee428e1
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69942dffdd8c76000896c640

@github-actions
Copy link
Contributor

Benchmarks Rust

  • target: main(d744c08)
  • pr: 02-17-fix_rolldown_plugin_esm_external_require_apply_conversion_to_umd_and_iife_outputs(b66de59)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     71.2±2.43ms        ? ?/sec    1.01     72.0±2.64ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     77.8±1.43ms        ? ?/sec    1.02     79.5±2.37ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00    103.9±3.38ms        ? ?/sec    1.01    104.9±2.52ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    115.2±2.94ms        ? ?/sec    1.02    118.0±2.90ms        ? ?/sec
bundle/bundle@threejs                                        1.03     37.5±0.91ms        ? ?/sec    1.00     36.3±0.56ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     41.8±0.74ms        ? ?/sec    1.01     42.4±0.88ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    376.8±4.08ms        ? ?/sec    1.01    381.1±9.52ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    434.2±7.89ms        ? ?/sec    1.02    442.2±7.53ms        ? ?/sec
scan/scan@rome_ts                                            1.00     77.9±1.65ms        ? ?/sec    1.01     78.5±1.87ms        ? ?/sec
scan/scan@threejs                                            1.00     27.5±0.36ms        ? ?/sec    1.00     27.4±0.46ms        ? ?/sec
scan/scan@threejs10x                                         1.00    272.9±3.75ms        ? ?/sec    1.00    271.6±6.36ms        ? ?/sec

Copy link
Member Author

sapphi-red commented Feb 17, 2026

Merge activity

  • Feb 17, 7:34 AM UTC: The merge label 'graphite: merge-when-ready' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Feb 17, 8:59 AM UTC: sapphi-red added this pull request to the Graphite merge queue.
  • Feb 17, 9:10 AM UTC: Merged by the Graphite merge queue.

…d IIFE outputs (#8359)

`require` is left as-is for https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for UMD output  and IIFE output ([REPL UMD](https://repl.rolldown.rs/#eNptkMFuwyAMhl/F4kIqRfQeaac9xrIDSUzLREwHZssU8e5z6NZdJiHAn3//lr0rp4ZdeVpwM2/5+JMa/uJezRLOkTJDQjszPMn7XnzCTjegT2Ma6VDEgCbES9dwo1KOauBUsPYqxRCW+ElGtM5fDD+6/ZO59/XrLSaGHRZ0nvC5paGCS3EF/VumRxoJtyYVoS2hvY+Cbh8JwNOt8AB3S7MiW9NQD+cz8BXB+YAZMgacGReYvhqdCnMkkCNTXYHtdJjFws2tOQO4mFYroS7rovuD1XbjxpjIhgFefpb1KryeZDNVNvIhIwbLmFnVb1kKh3g=), [REPL IIFE](https://repl.rolldown.rs/#eNptUEFuxCAM/IrFhawUsfdIPfUZpQeSmF0qYrbEtKki/l7ibbeXSgjb4/FYnl15Newq0IybeVuPnNTwV/dqauWUaGXI6CaGpxbfS8jYaQH0yWZLByNFNDFdOoEFbeOoBs4Fa69yinFOn2Qa14eL4ce2fzr3vWG5pcyww4w+ED5LGyr4nBbQv2PakiXchNqIrkSJj4FutwQQ6FZ4gLukWZCdEaiH8xn4iuBDxBVWjDgxzjB+CToW5kTQXrvqCuzGQywVFjVRBvApL66VOgSPuj/AKj9ujJlcHODlx61XS/XUnKnNkY92YnSMK6v6DV2Ph6M=)). That said, there's no way to achieve the on-demand execution semantics of `require` in AMD and IIFE, and thus it's not possible to achieve that in UMD as well.

This means we cannot add support internally like we do with CJS output and the user has to handle these cases. However, the `esmExternalRequirePlugin` only did the require -> import conversion for ESM outputs ([REPL UMD](https://repl.rolldown.rs/#eNp1UbFOxDAM/RUrS+6kqrcXMSF2xEoZcq17F5Q6JXGgqOq/k7qlDHBSFMfP7/k5yaQ6VU3KUotj+RaXM6nqNy9Uk9PGU2QIaBqG+xzfkw140ALoYx1qWhjeYen85SCwoFmOquKQcC5U8M61/pPKzO3speTd7Z/K6mv7wQeGCVrsLOGDlGGGLvge9I9M17QTMfaPI2Mg457XMZ9culj6IzoNgkd9V1NNOIo+25jkJO52h6kmAEtD4gpWn7JHNqVABZxOwFeEzjqMENFhw9jC+UvQc2L2BHnlN7kCm/PSzCeWbtIZoPOhNznVqW91sWCz7NuEFbysvFt3WycUxlbOku1zXtfSfFxiTpaDmvNvfOTndYYxspq/Ae6Ts1U=), [REPL IIFE](https://repl.rolldown.rs/#eNp1UcFOwzAM/RUrl2xS1d2LOCHuiCvlkLXOFpQ6I3FgqOq/k7qlHGBSFMfP7/k5yaisakblqMdr/ZbmM6nmN69UV9IuUGKIaDqG+xLfs4u40wLofRtbmhnBY+3DaSewoEWOquGYcapUDN734ZPqwrXuVPPm9k9l8XXDJUSGEXq0jvBByjCBjWEA/SPTLW1ETMPjlTGS8c/LmE8+nxz9ER0ugid911JLeBV9sTHZS9zsdmNLAI4umRtYfOoB2dQCVXA4AJ8RrPOYIKHHjrGH45egx8wcCMoqb3IGNse5Wcgs3aQzgA1xMCXVzlnU1QxOsq8jNvCyEG9dbhlRGGu5SNbfeV1K036OJZkPairf8VHe1xvGxGr6BqPos6w=)).

This PR changes the `esmExternalRequirePlugin` to also handle UMD output and IIFE output.

fixes #8349
@graphite-app graphite-app bot force-pushed the 02-17-fix_rolldown_plugin_esm_external_require_apply_conversion_to_umd_and_iife_outputs branch from b66de59 to ee428e1 Compare February 17, 2026 08:59
@graphite-app graphite-app bot merged commit ee428e1 into main Feb 17, 2026
34 checks passed
@graphite-app graphite-app bot deleted the 02-17-fix_rolldown_plugin_esm_external_require_apply_conversion_to_umd_and_iife_outputs branch February 17, 2026 09:10
shulaoda pushed a commit that referenced this pull request Feb 18, 2026
## [1.0.0-rc.5] - 2026-02-18

💡 Smarter `entriesAware` Manual Code Splitting                                                                 
                                             
New `entriesAware` and `entriesAwareMergeThreshold` options for `manualCodeSplitting.groups[]` enable              
entry-reachability-based chunk splitting with automatic small chunk merging.                                       
                                                                                                                   
- `entriesAware: true` splits matched modules by entry reachability — modules reached by the same set of entries are grouped together, providing the most precise loading behavior with less over-fetching
- Chunks now get more readable names reflecting their entry associations (e.g. `vendor-entry-a-entry-b.js`) instead of opaque hashes
- `entriesAwareMergeThreshold` sets a byte-size threshold to merge tiny subgroups into the closest sibling with the fewest extra entries, reducing micro-chunk fragmentation while preserving precision
- Recommended to use together with `maxSize`: merge tiny chunks first to reduce request overhead, then cap large chunks to control payload size

```js
manualCodeSplitting: {
  groups: [{
    name: 'vendor',
    test: /node_modules/,
    entriesAware: true,
    entriesAwareMergeThreshold: 28000, // bytes
  }]
}
```

### 🚀 Features

- add `Visitor` to `rolldown/utils` (#8373) by @sapphi-red
- module-info: add `inputFormat` property to `ModuleInfo` (#8329) by @shulaoda
- default `treeshake.invalid_import_side_effects` to `false` (#8357) by @sapphi-red
- rolldown_utils: add `IndexBitSet` (#8343) by @sapphi-red
- rolldown_utils: add more methods and trait impls to BitSet (#8342) by @sapphi-red
- rolldown_plugin_vite_build_import_analysis: add support for `await import().then((m) => m.prop)` (#8328) by @sapphi-red
- rolldown_plugin_vite_reporter: support custom logger for build infos (#7652) by @shulaoda
- rust/mcs: support `entriesAwareMergeThreshold` (#8312) by @hyf0
- mcs: `maxSize` will split the oversized chunk with taking file relevance into account (#8277) by @hyf0
- rolldown_plugin_vite_import_glob: support template literal in glob import patterns (#8298) by @shulaoda
- rolldown_plugin_chunk_import_map: output importmap without spaces (#8297) by @sapphi-red
- add INEFFECTIVE_DYNAMIC_IMPORT warning in core (#8284) by @shulaoda
- mcs: generate more readable name for `entriesAware` chunks (#8275) by @hyf0
- mcs: support `entriesAware` (#8274) by @hyf0

### 🐛 Bug Fixes

- improve circular dependency detection in chunk optimizer (#8371) by @IWANABETHATGUY
- align `minify.compress: true` and `minify.mangle: true` with `minify: true` (#8367) by @sapphi-red
- rolldown_plugin_esm_external_require: apply conversion to UMD and IIFE outputs (#8359) by @sapphi-red
- cjs: bailout treeshaking on cjs modules that have multiple re-exports (#8348) by @hyf0
- handle member expression and this expression in JSX element name rewriting (#8323) by @IWANABETHATGUY
- pad `encode_hash_with_base` output to fixed length to prevent slice panics (#8320) by @shulaoda
- `xxhash_with_base` skips hashing when input is exactly 16 bytes (#8319) by @shulaoda
- complete `ImportKind::try_from` with missing variants and correct `url-import` to `url-token` (#8310) by @shulaoda
- mark Node.js builtin modules as side-effect-free when resolved via `external` config (#8304) by @IWANABETHATGUY
- mcs: `maxSize` should split chunks correctly based on sizes (#8289) by @hyf0

### 🚜 Refactor

- introduce `RawMangleOptions` and `RawCompressOptions` (#8366) by @sapphi-red
- mcs: refactor `apply_manual_code_splitting` into `ManualSplitter` (#8346) by @hyf0
- rolldown_plugin_vite_reporter: simplify hook registration and remove redundant state (#8322) by @shulaoda
- use set to store user defined entry modules (#8315) by @IWANABETHATGUY
- rust/mcs: collect groups into map at first for having clean and performant operations (#8313) by @hyf0
- mcs: introduce newtype `ModuleGroupOrigin` and `ModuleGroupId` (#8311) by @hyf0
- remove unnecessary `FinalizerMutableState` struct (#8303) by @shulaoda
- move module finalization into `finalize_modules` (#8302) by @shulaoda
- extract `apply_transfer_parts_mutation` into its own module (#8301) by @shulaoda
- move ESM format check into `determine_export_mode` (#8294) by @shulaoda
- remove `warnings` field from `GenerateContext` (#8293) by @shulaoda
- extract util function remove clippy supression (#8290) by @IWANABETHATGUY
- move `is_in_node_modules` to `PathExt` trait in `rolldown_std_utils` (#8286) by @shulaoda
- rolldown_plugin_vite_reporter: remove unnecessary ineffective dynamic import detection logic (#8285) by @shulaoda
- dev: inject hmr runtime to `\0rolldown/runtime.js` (#8234) by @hyf0
- improve naming in chunk_optimizer (#8287) by @IWANABETHATGUY
- simplify PostChunkOptimizationOperation from bitflags to enum (#8283) by @IWANABETHATGUY
- optimize BitSet.index_of_one to return iterator instead of Vec (#8282) by @IWANABETHATGUY

### 📚 Documentation

- change default value in `format` JSDoc from `'esm'` to `'es'` (#8372) by @shulaoda
- in-depth: remove `invalidImportSideEffects` option mention from lazy barrel optimization doc (#8355) by @sapphi-red
- mcs: clarify `minSize` constraints (#8279) by @ShroXd

### ⚡ Performance

- use IndexVec for chunk TLA detection (#8341) by @sapphi-red
- only invoke single resolve call for the same specifier and import kind (#8332) by @sapphi-red
- rolldown_plugin_vite_reporter: skip gzip computation when `report_compressed_size` is disabled (#8321) by @shulaoda

### 🧪 Testing

- use `vi.waitFor` and `expect.poll` instead of custom `waitUtil` function (#8369) by @sapphi-red
- rolldown_plugin_esm_external_require_plugin: add tests (#8358) by @sapphi-red
- add watch file tests (#8330) by @sapphi-red
- rolldown_plugin_vite_build_import_analysis: add test for dynamic import treeshaking (#8327) by @sapphi-red

### ⚙️ Miscellaneous Tasks

- prepare-release: skip workflow on forked repositories (#8368) by @shulaoda
- format more files (#8360) by @sapphi-red
- deps: update oxc to v0.114.0 (#8347) by @camc314
- deps: update test262 submodule for tests (#8354) by @sapphi-red
- deps: update crate-ci/typos action to v1.43.5 (#8350) by @renovate[bot]
- deps: update oxc apps (#8351) by @renovate[bot]
- rolldown_plugin_vite_reporter: remove unnecessary README.md (#8334) by @shulaoda
- deps: update npm packages (#8338) by @renovate[bot]
- deps: update rust crates (#8339) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.13.0 (#8337) by @renovate[bot]
- deps: update github-actions (#8336) by @renovate[bot]
- deps: update napi to v3.8.3 (#8331) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.12.2 (#8325) by @renovate[bot]
- remove unnecessary transform.decorator (#8314) by @IWANABETHATGUY
- deps: update dependency rust to v1.93.1 (#8305) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.12.1 (#8300) by @renovate[bot]
- deps: update oxc apps (#8296) by @renovate[bot]
- docs: don't skip for build runs without cache (#8281) by @sapphi-red
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Vite 8 UMD builds with external dependencies from globals

3 participants