fix: preserve createRequire().resolve with literal import.meta.url when requireResolve is disabled#14491
fix: preserve createRequire().resolve with literal import.meta.url when requireResolve is disabled#14491JSerFeng wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes createRequire(import.meta.url).resolve(...) semantics when module.parser.javascript.requireResolve is disabled by preserving the literal import.meta.url (instead of baking it to a build-time file:// URL), so runtime require.resolve behaves relative to the emitted output module rather than the source path. It also adds a targeted warning when this preserved literal would land in CommonJS output (where import.meta is a runtime syntax error).
Changes:
- Preserve
createRequire(...)arguments verbatim whenrequireResolve: false, avoiding build-timefile://baking for cases likeimport.meta.url. - Emit an
Unsupported featurewarning when preservedcreateRequire(import.meta.url)would be emitted into a CJS bundle. - Add/adjust test coverage: new ESM snapshot case for runtime-preserved
.resolve, plus a CJS warning errorCase; simplify the older configCase accordingly.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rspack_plugin_javascript/src/parser_plugin/common_js_imports_parse_plugin.rs | Changes createRequire argument replacement behavior under requireResolve: false and adds a CJS-only warning for preserved import.meta.url. |
| tests/rspack-test/esmOutputCases/create-require/import-meta-url-resolve-disabled/rspack.config.js | Enables createRequire and disables requireResolve for the new ESM output test case. |
| tests/rspack-test/esmOutputCases/create-require/import-meta-url-resolve-disabled/index.js | Verifies literal import.meta.url is preserved and .resolve remains runtime-resolved while require() is still bundled. |
| tests/rspack-test/esmOutputCases/create-require/import-meta-url-resolve-disabled/dep.js | Simple dependency used to confirm require() calls are still bundled. |
| tests/rspack-test/esmOutputCases/create-require/import-meta-url-resolve-disabled/snapshots/esm.snap.txt | Snapshot asserting the emitted ESM output contains preserved createRequire(import.meta.url) and runtime .resolve(...). |
| tests/rspack-test/errorCases/create-require-resolve-disabled-cjs.js | New errorCase asserting the CJS-output warning is emitted (and no errors). |
| tests/rspack-test/fixtures/errors/create-require-resolve-disabled-cjs.js | Fixture that triggers preserved createRequire(import.meta.url) under CJS output to validate warning behavior. |
| tests/rspack-test/configCases/require/module-require-disable-resolve/index.js | Refocuses the existing configCase on dependency/side-effect preservation for non-statically-analyzable arguments. |
| tests/rspack-test/configCases/require/module-require-disable-resolve/a.js | Removed (no longer needed by the refocused configCase). |
| tests/rspack-test/configCases/require/module-require-disable-resolve/foo/a.js | Removed (no longer needed by the refocused configCase). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f1ef5a3b0d
ℹ️ 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".
📦 Binary Size-limit
❌ Size increased by 12.00KB from 67.82MB to 67.84MB (⬆️0.02%) |
Merging this PR will not alter performance
Comparing Footnotes
|
d502c34 to
b9f0132
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b9f0132f93
ℹ️ 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".
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 5 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 popular-libsPath:
📁 react-10kPath:
📁 react-1kPath:
📁 ui-componentsPath:
📁 react-5kPath:
Generated by Rsdoctor GitHub Action |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b9f0132f93
ℹ️ 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".
d2a55d9 to
950a0f6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 950a0f616c
ℹ️ 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".
950a0f6 to
d8e910c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8e910c2e4
ℹ️ 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".
a472962 to
a9aae53
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a9aae53321
ℹ️ 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".
a9aae53 to
1336a8a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1336a8aaa4
ℹ️ 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".
1336a8a to
6182710
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6182710f0d
ℹ️ 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".
5826e44 to
7552125
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7552125e52
ℹ️ 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".
7552125 to
69b21ce
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 69b21ce9c5
ℹ️ 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".
69b21ce to
e888c24
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e888c2444b
ℹ️ 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".
e888c24 to
1ce3cff
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ce3cff97d
ℹ️ 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".
1ce3cff to
2fc1e3c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2fc1e3cdb0
ℹ️ 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".
2fc1e3c to
cfefb56
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cfefb564d6
ℹ️ 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".
cfefb56 to
b6f2e5e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b6f2e5eb50
ℹ️ 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".
…en requireResolve is disabled
When `module.parser.javascript.requireResolve` is `false`, a created require's
`.resolve(...)` is preserved to run at runtime instead of being rewritten to a
module id.
A created require that is used as a real require object — `.resolve(...)`, any
other member (`r.main`, `r.resolve.paths(...)`, ...), or as a bare value
(`helper(r)`, `export { r }`, ...) — is kept and rendered via rspack's injected
`__rspack_createRequire` helper, so the literal `import.meta.url` resolves
relative to the runtime output module and those accesses hit the real require
(instead of a context-require / unsupported-member rewrite). A plain invoke
`r("./x")` is still bundled and `r.cache` still maps to the module cache, so a
created require used only that way is cleared to `undefined` — no dead
`import.meta.url` leaks and CommonJS output stays valid. The keep/clear decision
is deferred to `finish()`.
Since literal `import.meta.url` is only valid in ESM output, an `Unsupported
feature` warning is emitted when a kept `createRequire(import.meta.url)` would
land in a CommonJS bundle.
b6f2e5e to
ae6d86c
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
When
module.parser.javascript.requireResolveisfalse, a created require's.resolve(...)is preserved to run at runtime instead of being rewritten to a module id.The created require is treated as a real require object whenever it is used as one — decided per declaration:
.resolve(...)(incl. the 2-argrequire.resolve(request, options)form), any other member (r.main,r.resolve.paths(...), ...), or used as a bare value (helper(r),export { r },return r, ...) → the declaration is kept and rendered via rspack's injected__rspack_createRequirehelper, and those accesses hit the real require. (webpack instead rewrites value-use to a context-require + "Critical dependency" warning, and non-cache/resolvemembers toundefined+ "unsupported" warning — this is the improvement.)r("./x")is still bundled (__webpack_require__), andr.cachestill maps to the bundler module cache./* createRequire() */ undefined— no deadimport.meta.urlleaks and CommonJS output stays valid.The keep/clear decision is deferred to the parser's
finish()(the callee is left un-walked so a clear doesn't collide with an import-specifier rewrite; the kept case re-renders the callee as__rspack_createRequire). The kept literalimport.meta.urlhonors a customizedoutput.importMetaName.Since literal
import.meta.urlis only valid in ESM output, anUnsupported featurewarning is emitted when a keptcreateRequire(import.meta.url)would land in a CommonJS bundle.Tests
esmOutputCases/create-require/import-meta-url-resolve-disabled— ESM keep via helper, variable + inline forms, 2-arg resolve, extra-arg side effect; snapshot.configCases/require/create-require-kept-for-access— value-position use + non-resolve member access keep the real created require (no context-require/unsupported rewrite, no warning); invoke still bundled.configCases/require/create-require-no-resolve-no-leak— used only as invokes → cleared toundefined, valid CJS, no warning.configCases/require/create-require-resolve-disabled-cjs— CommonJS warning + artifact.configCases/require/create-require-resolve-custom-import-meta-name— kept argument honorsoutput.importMetaName.configCases/require/module-require-disable-resolve— dynamic-argument dependency preservation.Related links
Checklist