When building a TanStack Start + Nitro app in a pnpm monorepo where a workspace package
uses use-sync-external-store/shim alongside @auth0/auth0-react, Nitro's SSR bundle leaves
an unbundled __require("react") call in a CJS shim factory. The runner stage has no
node_modules, so this call fails on every SSR request with Cannot find module 'react'.
This is not Alpine/musl-specific — the same error occurs on Debian/glibc images. It only
works on macOS local dev because node_modules is present in the project tree, allowing
Node.js to resolve react via normal module resolution.
Rolldown splits the SSR bundle into multiple chunks. When @auth0/auth0-react is present,
Auth0 and React end up bundled together in _libs/auth0__auth0-react+react.mjs which exports
an inlined require_react. However, use-sync-external-store/shim (from a separate workspace
package) ends up in a different SSR chunk (_ssr/app-*.mjs) that does not have access to
the inlined React. Instead it uses:
var require_use_sync_external_store_shim_production = /* @__PURE__ */ __commonJSMin(((exports) => {
var React = __require("react"); // ← __require = createRequire(import.meta.url)
...
}));__require is createRequire(import.meta.url) — a real Node.js require(). Because the
Nitro runner stage only copies .output/ (not node_modules), require("react") has
nothing to resolve against and throws.
| Version | |
|---|---|
| Node.js | 24 |
| pnpm | 10.28.0 |
react |
19.2.3 |
nitro |
3.0.260311-beta |
@tanstack/react-start |
1.167.9 |
@auth0/auth0-react |
^2.16.0 |
use-sync-external-store |
^1.5.0 |
vite |
^8.0.3 (Rolldown) |
packages/
ui/ ← workspace package with use-sync-external-store/shim + Radix UI
web/ ← TanStack Start app, depends on @repro/ui + @auth0/auth0-react
Dockerfile ← Alpine runner (reproduces)
Dockerfile.glibc ← Debian runner (also reproduces — not Alpine-specific)
git clone <this-repo>
cd nitro-rolldown-musl-repro
# Build and run (Alpine — fails)
docker build -t repro .
docker run -p 3000:3000 repro
curl http://localhost:3000/Server starts but crashes on the first SSR request:
Error: Cannot find module 'react'
Require stack:
- /app/.output/server/_ssr/app-<hash>.mjs
at Module._resolveFilename (node:internal/modules/cjs/loader:1456:15)
...
code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/.output/server/_ssr/app-<hash>.mjs' ]
Nitro's server bundle should be fully self-contained. CJS shim packages like
use-sync-external-store/shim that transitively require react should have React
bundled inline — not left as an external require() that relies on node_modules
being present at runtime.
After pnpm run build, copy React into the server output before the runner stage:
node -e "
const fs = require('fs'), path = require('path');
const r = path.dirname(require.resolve('react/package.json'));
fs.cpSync(r, '.output/server/node_modules/react', { recursive: true, dereference: true });
"In a Dockerfile, add this immediately after RUN pnpm run build.