fix(rsc): convert vendored react-server-dom-webpack to ESM#1203
Closed
remorses wants to merge 2 commits intovitejs:mainfrom
Closed
fix(rsc): convert vendored react-server-dom-webpack to ESM#1203remorses wants to merge 2 commits intovitejs:mainfrom
remorses wants to merge 2 commits intovitejs:mainfrom
Conversation
The vendor-react-server-dom build plugin copies react-server-dom-webpack into dist/vendor/ as raw CJS. These use require() and module.exports which break on pure ESM runtimes (Cloudflare Workers, Deno Deploy) when bundled with resolve.noExternal: true. Adds an esbuild conversion step in the tsdown build config that converts each CJS entry file to self-contained ESM in-place, then removes the now-unused cjs/ subdirectory. Session: ses_22b5a7d8affeczTeFI1DGoYPd5
76cedcc to
f89b597
Compare
Do not force process.env.NODE_ENV to production while converting vendored React Server DOM files. Leaving the condition for the final Vite build keeps React Server DOM in the same development or production mode as React itself, including builds that run under NODE_ENV=test. Session: ses_22b5a7d8affeczTeFI1DGoYPd5
Contributor
|
Closing as the reproduction doesn't look right. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1204
Reproduction: https://github.com/remorses/vite-rsc-cloudflare-cjs-repro
@vitejs/plugin-rscvendorsreact-server-dom-webpackintodist/vendor/as raw CJS. These userequire()andmodule.exports, which break on pure ESM runtimes (Cloudflare Workers, Deno Deploy).optimizeDepshandles CJS-to-ESM conversion in dev mode, but it doesn't run duringvite build. In production, Rolldown handles CJS files directly by wrapping them in__commonJS+ a__requireshim. This shim falls back to the realrequireglobal when its internal routing can't resolve the target. On Cloudflare Workers,requiredoesn't exist.Shipping ESM vendor files eliminates the problem entirely since there's no CJS interop layer involved.
Adds an esbuild post-processing step in
tsdown.config.tsthat converts each CJS entry file to self-contained ESM with properimport/exportstatements. Removes thecjs/subdirectory after conversion. All 424 existing tests pass.