Skip to content
Source
Sign inSign up
TanStack/router

fix(start-plugin-core): write Rsbuild virtual modules under the app's root, not the working directory #8868

OpenSheraff(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromstart-plugin-core/rsbuild-virtual-modules-rootopened

Showing 5 changed files with 85 additions and 57 deletions (loading 2).

x
0 of 5 viewed, 5 left
5 additions and 0 deletions.changeset/rsbuild-virtual-modules-root.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/start-plugin-core': patch
+---
+​
+Rsbuild: Start writes its virtual modules under the app's root, not the working directory. An app built or served from another directory (`rsbuild build --root <app>` from a monorepo root) no longer fails with "Module not found" on the packages they import, such as RSC's serialization adapters.
12 additions and 9 deletionspackages/start-plugin-core/src/rsbuild/plugin.tsModified
View file
@@ -1,5 +1,5 @@
import { existsSync, readdirSync, realpathSync, statSync } from 'node:fs'
-import { dirname, join, resolve } from 'node:path'
+import { dirname, isAbsolute, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { joinURL } from 'ufo'
import {
@@ -113,10 +113,15 @@
// 1. modifyRsbuildConfig — resolve config, set up environments
// ---------------------------------------------------------------
api.modifyRsbuildConfig((rsbuildConfig, { mergeRsbuildConfig }) => {
- const root =
- typeof rsbuildConfig.root === 'string'
+ // Rsbuild passes `root` on as written; its resolved root (against its
+ // `cwd`) is `rootPath`. Canonical (no trailing separator), as the
+ // virtual modules' paths must match Rspack's module paths.
+ const root = resolve(
+ typeof rsbuildConfig.root === 'string' &&
+ isAbsolute(rsbuildConfig.root)
? rsbuildConfig.root
- : process.cwd()
+ : api.context.rootPath,