Standalone output omits react when the app bundles it, but the prod server itself imports react
Summary
When the app's server bundle does not leave react external, vinext build with output: "standalone" produces a dist/standalone that cannot boot: vinext's own prod server imports react, but the standalone copier does not include it.
emitStandaloneOutput (packages/vinext/src/build/standalone.ts:254) copies:
- the packages in
dist/server/vinext-externals.json(line 315), and - vinext's own runtime deps via
runtimeDeps(vinextPkg)(line 345), which isdependencies+optionalDependenciesonly (lines 43-48).
react and react-dom are peerDependencies of vinext, so they only get copied when the app bundle happens to list them as externals. Files under vinext/dist/server/ (for example app-render-dependency.js, app-elements-wire.js) import react directly.
(line numbers at the [email protected] tag; same on main.)
Repro (vinext 1.0.0-beta.12, react 19.3.0, vite 8.3.1, Node 24.14)
Trivial App Router app (app/layout.jsx, app/page.jsx), next.config.mjs = { output: "standalone" }, and a vite config that removes react from the SSR externals (react is hard-coded there, see #3485):
// vite.config.mjs
import vinext from "vinext";
import { defineConfig } from "vite";
const REACT = ["react", "react-dom", "react-dom/server"];
const strip = (ext) => (Array.isArray(ext) ? ext.filter((x) => !REACT.includes(x)) : ext);
const bundleReact = {
name: "bundle-react",
enforce: "post",
config(cfg) { if (cfg.ssr?.external) cfg.ssr.external = strip(cfg.ssr.external); },
configEnvironment(_n, cfg) { if (cfg.resolve?.external) cfg.resolve.external = strip(cfg.resolve.external); },
};
export default defineConfig({ plugins: [vinext(), bundleReact] });npx vinext build
cat dist/server/vinext-externals.json # []
ls dist/standalone/node_modules | grep -E '^(react|react-dom)$' # nothing
cp -R dist/standalone /some/empty/dir && cd /some/empty/dir && node server.jsError [ERR_MODULE_NOT_FOUND]: Cannot find package 'react' imported from /some/empty/dir/node_modules/vinext/dist/server/app-render-dependency.jsCopying react, react-dom and scheduler into dist/standalone/node_modules fixes it (GET / returns 200 with the page).
Suggestion
The standalone copier should include the prod server's own peer dependencies (react, react-dom) regardless of what the app bundle externalized, e.g. add the resolvable peerDependencies of vinext to the runtimeDeps set, resolved from the app root so the app's react version wins.
A side effect worth knowing about: with react bundled into the SSR output and also imported by the prod server, there are two copies of React at runtime. Pages render because elements cross via Symbol.for, but hooks or context crossing that boundary would not. Longer term it might be cleaner for the prod server to get react from the server bundle rather than importing it itself, but copying the peer deps is the small fix.
Related: #3443 (the same copier picks the wrong package version when several are installed), #3445, #3476.
Source: cloudflare/vinext