Skip to content

feat(core): use modern-module externals type for Node ESM#1672

Open
Timeless0911 wants to merge 4 commits into
mainfrom
david/modern-module-externals
Open

feat(core): use modern-module externals type for Node ESM#1672
Timeless0911 wants to merge 4 commits into
mainfrom
david/modern-module-externals

Conversation

@Timeless0911
Copy link
Copy Markdown
Contributor

@Timeless0911 Timeless0911 commented May 26, 2026

Summary

This PR changes the default ESM externalsType to modern-module only for output.target: 'node', so CommonJS require() externals in Node ESM output use Rspack's modern createRequire handling. Browser ESM output keeps the previous module-import default to avoid emitting Node-specific node:module code paths.

It also removes the old CommonJS external warning path and the now-unneeded autoCjsNodeBuiltin RslibPlugin option, then updates the externals docs and integration coverage for node/web ESM behavior and supported external type forms.

Related Links

https://rspack.rs/config/externals#externalstypemodern-module
https://rspack.rs/config/externals#externalstypemodule-import

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings May 26, 2026 12:08
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 26, 2026

Deploying rslib with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7baca3e
Status: ✅  Deploy successful!
Preview URL: https://175bfc21.rslib.pages.dev
Branch Preview URL: https://david-modern-module-external.rslib.pages.dev

View logs

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 87ff22e106

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/config.ts
Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
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

Copilot reviewed 16 out of 17 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

@Timeless0911 Timeless0911 changed the title feat(core): use modern-module externals type for esm feat(core): use modern-module externals type for Node ESM May 27, 2026
@Timeless0911 Timeless0911 force-pushed the david/modern-module-externals branch from bcf4bbe to 28f0e83 Compare May 28, 2026 08:58
@Timeless0911
Copy link
Copy Markdown
Contributor Author

pending

  1. Rspack support bundle createRequire
  2. modern-module external type now depends externalsPreset.node to determine node target, but Rslib set externalsPreset.node to false since fix: remove externalsPresets.node #1318 due to externals: { fs: false } can not takes effect with externalsPreset which should be a bug of Rspack externals?

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7baca3eb91

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


const externalsTypeMap: Record<Format, Rspack.ExternalsType> = {
esm: 'module-import',
esm: 'modern-module',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Gate modern-module default to Node targets

For format: 'esm' with output.target: 'web', this default now applies modern-module to auto/user externals as well; the current patch’s own docs (website/docs/en/config/rsbuild/output.mdx line 90) confirm that CommonJS require() externals on non-Node targets are emitted as bare require() calls. That regresses web-target ESM bundles that externalize a dependency used via require() (including auto-external dependencies), because browsers do not provide require, whereas the previous module-import fallback emitted ESM imports for these cases. Please keep module-import for web targets or make this mapping target-aware.

Useful? React with 👍 / 👎.

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.

2 participants