feat(core): use modern-module externals type for Node ESM#1672
feat(core): use modern-module externals type for Node ESM#1672Timeless0911 wants to merge 4 commits into
Conversation
Deploying rslib with
|
| Latest commit: |
7baca3e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://175bfc21.rslib.pages.dev |
| Branch Preview URL: | https://david-modern-module-external.rslib.pages.dev |
There was a problem hiding this comment.
💡 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".
bcf4bbe to
28f0e83
Compare
|
pending
|
There was a problem hiding this comment.
💡 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', |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
This PR changes the default ESM
externalsTypetomodern-moduleonly foroutput.target: 'node', so CommonJSrequire()externals in Node ESM output use Rspack's moderncreateRequirehandling. Browser ESM output keeps the previousmodule-importdefault to avoid emitting Node-specificnode:modulecode paths.It also removes the old CommonJS external warning path and the now-unneeded
autoCjsNodeBuiltinRslibPlugin 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