[plugin-rsc] In dev, a server component rendering `@mui/material/Button` breaks the page with "does not provide an export named 'default'"

未关闭
#1,538 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
12/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
react, typescript
领域
build-system

调研方向

Start with the client-in-server-package-proxy generation in packages/plugin-rsc/src/plugin.ts (around lines 1538-1555 and 1710-1730) and the packageSources.set call near line 1774, then reproduce with the linked starter in vite dev. Done means a server component importing @mui/material/Button renders in dev as it does in /?client and in the production build, with no prop-types export error.

由索引模型根据 Issue 内容生成。

描述

Claude Claude Opus 5.5 (high effort) wrote this; Claude Opus 5.5 (medium effort) reviewed it.

In vite dev, a server component that renders @mui/material/Button replaces the page with the error boundary, because the browser fails to load MUI's code. A build works. Waku, React Router's RSC Framework Mode and TanStack Start's RSC mode fail the same way in dev.

How to reproduce

The repro is plugin-rsc's starter (pnpm create vite@latest --template rsc) with @mui/material, @emotion/react and @emotion/styled added, and a <Button variant="contained"> in src/root.tsx: https://github.com/nitedani-agent/plugin-rsc-repro-inner-use-client-cjs

  1. pnpm i && pnpm dev, then open http://localhost:5173/
  2. You see the starter's error boundary, "Caught an unexpected error", and the console has:
    SyntaxError: The requested module '/node_modules/.pnpm/[email protected]/node_modules/prop-types/index.js?v=414bb9ec' does not provide an export named 'default'
    
  3. I expected the page with the MUI button, as pnpm build && pnpm preview shows, and as http://localhost:5173/?client shows in dev, where the same Button comes from a "use client" file of the app (src/client-mui-button.tsx).

It happens in vite dev, cold or warm cache, when all three hold:

  • A server component imports a package path whose file has no "use client", but re-exports by a relative path a file that has one. @mui/material/Button is Button/index.mjs, which re-exports ./Button.mjs. When the imported file is itself the "use client" file, it works.
  • That inner "use client" file imports a CommonJS package (prop-types in Button.mjs). When it imports only ESM files and react, which Vite already pre-bundles, it works. A two-file package importing react-is fails the same way (isValidElementType).
  • The import is in a server component. The same import in a "use client" file of the app (/?client) works.

Each framework's official RSC starter with the same page:

App, with a server component rendering the Button vite dev (cold and warm) Build, then start
This repro, plugin-rsc 0.5.38 error boundary works
Waku 1.0.0-rc.4 (plugin-rsc 0.5.38) Waku's error text replaces the page works
React Router 8.5.1, RSC Framework Mode (plugin-rsc 0.5.38) "Oops!" error boundary works on plugin-rsc 0.5.35 ¹
TanStack Start 1.169.4, RSC (plugin-rsc 0.5.38) "Something went wrong!" works
Next.js 16.4.3, webpack and Turbopack dev, Turbopack build (no plugin-rsc) works works

All four plugin-rsc apps show the same prop-types error. ¹ React Router's build fails on plugin-rsc 0.5.36+ for an unrelated reason (remix-run/react-router#15671).

@vitejs/plugin-rsc 0.5.38, @vitejs/plugin-react 6.1.2, vite 8.3.5
react, react-dom 19.3.1, @mui/material 9.5.0, @emotion/react 11.14.0, @emotion/styled 11.14.1
Node 26.12.1, Linux, pnpm 12.15.0
plugin-rsc's plugin.ts is the same on main (304a92a) as in 0.5.38

plugin-rsc records a package source only for the file a bare import resolves to (packageSources.set). The inner Button.mjs has none, so in dev the browser gets it through client-in-server-package-proxy (plugin.ts#L1538-L1555), which is export * from "<absolute path>" (#L1710-L1730). Vite doesn't add a new dependency to the pre-bundle when a file in node_modules imports it (resolve.ts#L835-L856), and nothing else pre-bundles prop-types here, so it reaches the browser as CommonJS.

Waku and TanStack Start print the "inconsistently optimized" warning for Button.mjs (#L1477-L1490), but its advice doesn't help: with optimizeDeps: { exclude: ['@mui/material'] } the repro fails with the same error. vike-react-rsc works around it by pre-bundling such a file in the client environment (clientInServerPackageDeps.ts).

#1207 reports a different failure in the same client-in-server-package-proxy.

主要语言
TypeScript
星标
1.2k
派生
287
平均合并
1 天 17 小时
30 天内合并 PR
19

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

vitejs/vite-plugin-react 的其他 Issue

查看 vitejs/vite-plugin-react 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。