Skip to content
Source
Sign inSign up
TanStack/router

fix(start-plugin-core): find Start libraries from Vite's root, not the working directory #8866

OpenSheraff(GitHub profile, opens in a new tab)wants to merge 5 commits intomain fromstart-plugin-core/vite-root-library-discoveryopened

Showing 3 changed files with 203 additions and 1 deletion.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/start-vite-root-library-discovery.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/start-plugin-core': patch
+---
+​
+Vite: Start finds the Start libraries it bundles in the SSR build from Vite's root, not the working directory. A `vite build <app>` run from another directory (a monorepo root, a script) no longer leaves them external and uncompiled, where their server fns returned `undefined`.
7 additions and 1 deletionpackages/start-plugin-core/src/vite/plugin.tsModified
View file
@@ -1,3 +1,5 @@
+import { realpathSync } from 'node:fs'
+import { resolve } from 'node:path'
import { crawlFrameworkPkgs } from 'vitefu'
import {
applyResolvedBaseAndOutput,
@@ -140,7 +142,11 @@
// see https://github.com/vitejs/vite/blob/557f797d29422027e8c451ca50dd84bf8c41b5f0/packages/vite/src/node/optimizer/index.ts#L1282
​
const crawlFrameworkPkgsResult = await crawlFrameworkPkgs({
- root: process.cwd(),
+ // (the configured root, which can be relative: resolved as Vite does,
+ // then physical, as Vite resolves the app's imports from there)
+ root: realpathSync(
+ viteConfig.root ? resolve(viteConfig.root) : process.cwd(),
+ ),
Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)
isBuild: command === 'build',
isFrameworkPkgByJson(pkgJson) {
const peerDependencies = pkgJson['peerDependencies']