Related plugins
Describe the bug
In a monorepo, when pkg-a imports & uses pkg-b in a server component, the pkg-b is imported in virtual:vite-rsc/client-references.
When the main workspace/app only installs pkg-a, it will fail with module resolution error like:
Error: [vite+]: Rolldown failed to resolve import "pkg-b" from "virtual:vite-rsc/client-references".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rolldownOptions.external`
I checked prior issues like #826 and https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-rsc/docs/architecture.md, not sure if this is intentional, but I think it's not a design flaw, it's possible to resolve directly to a transitive dep, the error only happens because Vite failed to resolve the transitive dep from workspace.
Currently, it will require a consumer to install all transitive deps of pkg-a as long as they'll be included in client-references, but this purely depends on how pkg-a uses its transitive deps, consumer has no control/awareness of this. It is adding a lot more complexity to consume RSC-native packages/libraries, I found it very difficult to do without making a custom Vite plugin to workaround this (but very fragile).
I have fixed this with a Vite plugin that simply hook on resolveId(), and replace it with the full resolved path of module. Would be great if the RSC plugin can use a similar strategy to prevent issues with transitive deps.
You can see my original fix here: https://github.com/fuma-nama/fumapress/blob/3998fcbd618d8d66faed4154a63fa7d93687c548/packages/core/src/vite.ts#L77
Reproduction
see fuma-nama/fumapress#39
Steps to reproduce
Although not a direct illustration, this is the original issue from Fumapress:
- Open a monorepo.
pnpm create fumapress@0.0.14, include the created project as a workspace of monorepo.
pnpm build on the workspace.
It should error on @fuma-translate/react, this is a transitive dependency of fumapress/fumadocs (declared in their package.json), in the context of pkg-a/pkg-b, pkg-a refers to Fumapress & pkg-b refers to @fuma-translate/react.
System Info
System:
OS: macOS 15.7.1
CPU: (12) arm64 Apple M3 Pro
Memory: 101.55 MB / 18.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.15.0 - /Users/xred/.nvm/versions/node/v24.15.0/bin/node
npm: 11.16.0 - /Users/xred/.nvm/versions/node/v24.15.0/bin/npm
pnpm: 11.1.1 - /Users/xred/.nvm/versions/node/v24.15.0/bin/pnpm
bun: 1.3.14 - /Users/xred/.nvm/versions/node/v24.15.0/bin/bun
Browsers:
Safari: 18.6
npmPackages:
vite: ^8.0.16 => 8.0.16
Used Package Manager
npm
Logs
No response
Validations
Related plugins
plugin-react
plugin-react-swc
plugin-rsc
Describe the bug
In a monorepo, when
pkg-aimports & usespkg-bin a server component, thepkg-bis imported invirtual:vite-rsc/client-references.When the main workspace/app only installs
pkg-a, it will fail with module resolution error like:I checked prior issues like #826 and https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-rsc/docs/architecture.md, not sure if this is intentional, but I think it's not a design flaw, it's possible to resolve directly to a transitive dep, the error only happens because Vite failed to resolve the transitive dep from workspace.
Currently, it will require a consumer to install all transitive deps of
pkg-aas long as they'll be included in client-references, but this purely depends on howpkg-auses its transitive deps, consumer has no control/awareness of this. It is adding a lot more complexity to consume RSC-native packages/libraries, I found it very difficult to do without making a custom Vite plugin to workaround this (but very fragile).I have fixed this with a Vite plugin that simply hook on
resolveId(), and replace it with the full resolved path of module. Would be great if the RSC plugin can use a similar strategy to prevent issues with transitive deps.You can see my original fix here: https://github.com/fuma-nama/fumapress/blob/3998fcbd618d8d66faed4154a63fa7d93687c548/packages/core/src/vite.ts#L77
Reproduction
see fuma-nama/fumapress#39
Steps to reproduce
Although not a direct illustration, this is the original issue from Fumapress:
pnpm create fumapress@0.0.14, include the created project as a workspace of monorepo.pnpm buildon the workspace.It should error on
@fuma-translate/react, this is a transitive dependency of fumapress/fumadocs (declared in theirpackage.json), in the context ofpkg-a/pkg-b,pkg-arefers to Fumapress &pkg-brefers to@fuma-translate/react.System Info
System: OS: macOS 15.7.1 CPU: (12) arm64 Apple M3 Pro Memory: 101.55 MB / 18.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.15.0 - /Users/xred/.nvm/versions/node/v24.15.0/bin/node npm: 11.16.0 - /Users/xred/.nvm/versions/node/v24.15.0/bin/npm pnpm: 11.1.1 - /Users/xred/.nvm/versions/node/v24.15.0/bin/pnpm bun: 1.3.14 - /Users/xred/.nvm/versions/node/v24.15.0/bin/bun Browsers: Safari: 18.6 npmPackages: vite: ^8.0.16 => 8.0.16Used Package Manager
npm
Logs
No response
Validations