#3485·vinext

react/react-dom are hard-coded SSR externals, so transpilePackages cannot bundle them (compiled server fails: Cannot find package react-dom)

Author: AhmedElBanna80Created Sep 26, 2026Updated Sep 26, 2026

Summary

transpilePackages removes a package from vinext's default server externals (mergeServerExternalPackages, packages/vinext/src/config/server-external-packages.ts:130-146), but react, react-dom and react-dom/server are hard-coded in the SSR externals and are not reachable that way:

  • packages/vinext/src/index.ts:3207-3217 (top-level ssr.external)
  • packages/vinext/src/index.ts:3761-3767 (environments.ssr.resolve.external)

(line numbers at the [email protected] tag; the same code is on main.)

So there is no config-level way to get a server build that does not need react/react-dom from node_modules at runtime. That matters when the server is compiled into a single executable, which is the shape discussed in #3476.

Repro (vinext 1.0.0-beta.12, react 19.3.0, vite 8.3.1, Bun 1.4.2, Node 24.14)

app/layout.jsx and app/page.jsx are a trivial layout and <h1>hello</h1>.

javascript
// next.config.mjs
export default { output: "standalone", transpilePackages: ["react", "react-dom"] };
bash
npx vinext build
cat dist/server/vinext-externals.json
# [ "react", "react-dom" ]

Compile the prod server with the app bundle as a second entrypoint and run it from a directory with no node_modules anywhere above it:

javascript
// dist/standalone/entry.mjs
import { dirname, join } from "node:path";
import { startProdServer } from "vinext/server/prod-server";
startProdServer({
  port: 3123,
  outDir: join(dirname(process.execPath), "dist"),
  rscEntryPath: "/$bunfs/root/dist/server/index.js",
});
bash
cd dist/standalone
bun build --compile --format=esm entry.mjs dist/server/index.js --outfile /some/empty/dir/server-bin
cp -R dist /some/empty/dir/dist
cd /some/empty/dir && ./server-bin
# GET / -> 500
[vinext] Server error: error: Cannot find package 'react-dom' from '/$bunfs/root/dist/server/index.js'

Bun bundles the static import ... from "react-dom" fine. What fails is a runtime require in dist/server/ssr/index.js: the vendored react-server-dom client is CJS, and the output calls createRequire(import.meta.url)("react-dom") (plus .resolve("react-dom/package.json") and import("react-dom/static.edge")). Inside the binary import.meta.url is under /$bunfs/root, so nothing resolves. Run from inside the project tree it works, because the lookup walks up into the project's node_modules.

What works

Stripping react from both external lists with an app-side plugin (enforce: "post", in config and configEnvironment) gives vinext-externals.json = [] and a server bundle that renders without runtime react resolution. The SSR environment ends up with one react and one react-dom chunk. (The standalone output then has a separate problem, filed as #3486.)

Suggestion

Honour transpilePackages for the hard-coded react entries in production builds, or add an explicit opt-in (for example a bundleReact / inline-server-externals option, which is the design question in #3476). I understand from the comment above the list that external react is deliberate because of duplicate-React crashes (#1103), so an opt-in that stays off by default seems like the safer shape.

Related on the Bun side: oven-sh/bun#44053 (an --external package in a compiled binary is resolved from process.cwd(), not the executable's directory), which is why leaving react external is not a workaround either.