From 6c430d12e4e5044bbbc7a82b14e56c21fce5ee8b Mon Sep 17 00:00:00 2001 From: James Opstad <13586373+jamesopstad@users.noreply.github.com> Date: Wed, 24 Sep 2025 20:00:21 +0100 Subject: [PATCH 1/6] Simplify aliases --- packages/start-plugin-core/src/plugin.ts | 37 ++++++++---------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/packages/start-plugin-core/src/plugin.ts b/packages/start-plugin-core/src/plugin.ts index d52dd4b849b..fb7a6f0c0c1 100644 --- a/packages/start-plugin-core/src/plugin.ts +++ b/packages/start-plugin-core/src/plugin.ts @@ -1,4 +1,3 @@ -import path from 'node:path' import { trimPathRight } from '@tanstack/router-core' import { VIRTUAL_MODULES } from '@tanstack/start-server-core' import { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin' @@ -134,37 +133,25 @@ export function TanStackStartVitePluginCore( required: false, }) - let clientAlias: string - if (clientEntryPath) { - clientAlias = vite.normalizePath( - path.join('/@fs', path.resolve(root, clientEntryPath)), - ) - } else { - clientAlias = corePluginOpts.defaultEntryPaths.client - } - - let serverAlias: string - if (serverEntryPath) { - serverAlias = vite.normalizePath(path.resolve(root, serverEntryPath)) - } else { - serverAlias = corePluginOpts.defaultEntryPaths.server - } - - let startAlias: string - if (startFilePath) { - startAlias = vite.normalizePath(path.resolve(root, startFilePath)) - } else { - startAlias = corePluginOpts.defaultEntryPaths.start - } + const clientAlias = vite.normalizePath( + clientEntryPath ?? corePluginOpts.defaultEntryPaths.client, + ) + const serverAlias = vite.normalizePath( + serverEntryPath ?? corePluginOpts.defaultEntryPaths.server, + ) + const startAlias = vite.normalizePath( + startFilePath ?? corePluginOpts.defaultEntryPaths.start, + ) + const routerAlias = vite.normalizePath(routerFilePath) const entryAliasConfiguration: Record< (typeof ENTRY_POINTS)[keyof typeof ENTRY_POINTS], string > = { - [ENTRY_POINTS.start]: startAlias, - [ENTRY_POINTS.router]: routerFilePath, [ENTRY_POINTS.client]: clientAlias, [ENTRY_POINTS.server]: serverAlias, + [ENTRY_POINTS.start]: startAlias, + [ENTRY_POINTS.router]: routerAlias, } const startPackageName = From 964c0492638bd61bea0edd343d9db68c9bdcdbf3 Mon Sep 17 00:00:00 2001 From: James Opstad <13586373+jamesopstad@users.noreply.github.com> Date: Wed, 24 Sep 2025 20:04:16 +0100 Subject: [PATCH 2/6] Add optimizeDeps.entries --- packages/react-start/src/plugin/vite.ts | 2 +- packages/start-plugin-core/src/plugin.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/react-start/src/plugin/vite.ts b/packages/react-start/src/plugin/vite.ts index a580a4522ac..3342bf4793e 100644 --- a/packages/react-start/src/plugin/vite.ts +++ b/packages/react-start/src/plugin/vite.ts @@ -65,7 +65,7 @@ export function tanstackStart( ? ['react-dom/client'] : ['react-dom/server']), // `@tanstack/react-store` has a dependency on `use-sync-external-store`, which is CJS. - // It therefore needs to included so that it is converted to ESM. + // It therefore needs to be included so that it is converted to ESM. '@tanstack/react-router > @tanstack/react-store', ], } diff --git a/packages/start-plugin-core/src/plugin.ts b/packages/start-plugin-core/src/plugin.ts index fb7a6f0c0c1..09957e1518d 100644 --- a/packages/start-plugin-core/src/plugin.ts +++ b/packages/start-plugin-core/src/plugin.ts @@ -193,10 +193,13 @@ export function TanStackStartVitePluginCore( }, outDir: getClientOutputDirectory(viteConfig), }, + optimizeDeps: { + // Ensure user code can be crawled for dependencies + entries: [clientAlias, routerAlias], + }, }, [VITE_ENVIRONMENT_NAMES.server]: { consumer: 'server', - build: { ssr: true, rollupOptions: { @@ -212,6 +215,10 @@ export function TanStackStartVitePluginCore( viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server] ?.build?.copyPublicDir ?? false, }, + optimizeDeps: { + // Ensure user code can be crawled for dependencies + entries: [serverAlias, startAlias, routerAlias], + }, }, }, From 763c7064d8432bda3a9e8c2ba371b5a055f10a78 Mon Sep 17 00:00:00 2001 From: James Opstad <13586373+jamesopstad@users.noreply.github.com> Date: Thu, 25 Sep 2025 12:48:29 +0100 Subject: [PATCH 3/6] Rename client and server ENTRY_POINTS --- packages/start-plugin-core/src/constants.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/start-plugin-core/src/constants.ts b/packages/start-plugin-core/src/constants.ts index 3f72297c81e..9ff3b4b0aa4 100644 --- a/packages/start-plugin-core/src/constants.ts +++ b/packages/start-plugin-core/src/constants.ts @@ -12,8 +12,8 @@ export type ViteEnvironmentNames = // if a user has a custom server/client entry point file, resolve.alias will point to this // otherwise it will be aliased to the default entry point in the respective framework plugin export const ENTRY_POINTS = { - client: 'virtual:tanstack-start-client-entry', - server: 'virtual:tanstack-start-server-request-entry', + client: '__tanstack-start-client-entry__', + server: '__tanstack-start-server-entry__', // the start entry point must always be provided by the user start: '#tanstack-start-entry', router: '#tanstack-router-entry', From 2761dd570bf8ff2cf7fcac5296982d150a063715 Mon Sep 17 00:00:00 2001 From: James Opstad <13586373+jamesopstad@users.noreply.github.com> Date: Thu, 25 Sep 2025 13:02:47 +0100 Subject: [PATCH 4/6] Escape optimizeDeps.entries paths --- packages/start-plugin-core/package.json | 1 + packages/start-plugin-core/src/plugin.ts | 11 +++++++++-- pnpm-lock.yaml | 15 +++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/start-plugin-core/package.json b/packages/start-plugin-core/package.json index cd151eb4878..623abcbf469 100644 --- a/packages/start-plugin-core/package.json +++ b/packages/start-plugin-core/package.json @@ -76,6 +76,7 @@ "exsolve": "^1.0.7", "pathe": "^2.0.3", "srvx": "^0.8.2", + "tinyglobby": "^0.2.15", "ufo": "^1.5.4", "vitefu": "^1.1.1", "xmlbuilder2": "^3.1.1", diff --git a/packages/start-plugin-core/src/plugin.ts b/packages/start-plugin-core/src/plugin.ts index 09957e1518d..e8f0a01953a 100644 --- a/packages/start-plugin-core/src/plugin.ts +++ b/packages/start-plugin-core/src/plugin.ts @@ -4,6 +4,7 @@ import { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin' import * as vite from 'vite' import { crawlFrameworkPkgs } from 'vitefu' import { join } from 'pathe' +import { escapePath } from 'tinyglobby' import { startManifestPlugin } from './start-manifest-plugin/plugin' import { startCompilerPlugin } from './start-compiler-plugin/plugin' import { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from './constants' @@ -195,7 +196,10 @@ export function TanStackStartVitePluginCore( }, optimizeDeps: { // Ensure user code can be crawled for dependencies - entries: [clientAlias, routerAlias], + entries: [clientAlias, routerAlias].map((entry) => + // Entries are treated as `tinyglobby` patterns so need to be escaped + escapePath(entry), + ), }, }, [VITE_ENVIRONMENT_NAMES.server]: { @@ -217,7 +221,10 @@ export function TanStackStartVitePluginCore( }, optimizeDeps: { // Ensure user code can be crawled for dependencies - entries: [serverAlias, startAlias, routerAlias], + entries: [serverAlias, startAlias, routerAlias].map((entry) => + // Entries are treated as `tinyglobby` patterns so need to be escaped + escapePath(entry), + ), }, }, }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 59146c07271..2dad4466297 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7063,6 +7063,9 @@ importers: srvx: specifier: ^0.8.2 version: 0.8.7 + tinyglobby: + specifier: ^0.2.15 + version: 0.2.15 ufo: specifier: ^1.5.4 version: 1.6.1 @@ -18254,10 +18257,10 @@ snapshots: '@rollup/pluginutils': 5.1.4(rollup@4.52.2) commondir: 1.0.1 estree-walker: 2.0.2 - fdir: 6.4.4(picomatch@4.0.2) + fdir: 6.5.0(picomatch@4.0.3) is-reference: 1.2.1 magic-string: 0.30.19 - picomatch: 4.0.2 + picomatch: 4.0.3 optionalDependencies: rollup: 4.52.2 @@ -18304,7 +18307,7 @@ snapshots: dependencies: '@types/estree': 1.0.7 estree-walker: 2.0.2 - picomatch: 4.0.2 + picomatch: 4.0.3 optionalDependencies: rollup: 4.52.2 @@ -19512,7 +19515,7 @@ snapshots: glob: 10.4.5 graceful-fs: 4.2.11 node-gyp-build: 4.8.4 - picomatch: 4.0.2 + picomatch: 4.0.3 resolve-from: 5.0.0 transitivePeerDependencies: - encoding @@ -19624,7 +19627,7 @@ snapshots: flatted: 3.3.2 pathe: 2.0.3 sirv: 3.0.1 - tinyglobby: 0.2.13 + tinyglobby: 0.2.15 tinyrainbow: 2.0.0 vitest: 3.2.4(@types/node@22.13.4)(@vitest/browser@3.0.6)(@vitest/ui@3.0.6)(jiti@2.6.0)(jsdom@25.0.1)(lightningcss@1.29.2)(msw@2.7.0(@types/node@22.13.4)(typescript@5.9.2))(terser@5.37.0)(tsx@4.20.3)(yaml@2.7.0) @@ -23492,7 +23495,7 @@ snapshots: rollup-plugin-visualizer@6.0.3(rollup@4.52.2): dependencies: open: 8.4.2 - picomatch: 4.0.2 + picomatch: 4.0.3 source-map: 0.7.6 yargs: 17.7.2 optionalDependencies: From 92ce7fe718ef1082d7c89c89a60516b1834ed2e9 Mon Sep 17 00:00:00 2001 From: James Opstad <13586373+jamesopstad@users.noreply.github.com> Date: Thu, 25 Sep 2025 13:44:09 +0100 Subject: [PATCH 5/6] Add extensions to default entry paths --- packages/react-start/src/plugin/vite.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-start/src/plugin/vite.ts b/packages/react-start/src/plugin/vite.ts index 3342bf4793e..bb896b32b35 100644 --- a/packages/react-start/src/plugin/vite.ts +++ b/packages/react-start/src/plugin/vite.ts @@ -16,9 +16,9 @@ const defaultEntryDir = path.resolve( 'default-entry', ) const defaultEntryPaths = { - client: path.resolve(defaultEntryDir, 'client'), - server: path.resolve(defaultEntryDir, 'server'), - start: path.resolve(defaultEntryDir, 'start'), + client: path.resolve(defaultEntryDir, 'client.tsx'), + server: path.resolve(defaultEntryDir, 'server.ts'), + start: path.resolve(defaultEntryDir, 'start.ts'), } const isInsideRouterMonoRepo = From 9e29f18bb51c17f41acee8a5f07276a874ac298e Mon Sep 17 00:00:00 2001 From: Manuel Schiller Date: Fri, 26 Sep 2025 05:43:56 +0200 Subject: [PATCH 6/6] sync solid --- packages/solid-start/src/plugin/vite.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/solid-start/src/plugin/vite.ts b/packages/solid-start/src/plugin/vite.ts index f9ad7d62f8a..c1131dc8392 100644 --- a/packages/solid-start/src/plugin/vite.ts +++ b/packages/solid-start/src/plugin/vite.ts @@ -16,9 +16,9 @@ const defaultEntryDir = path.resolve( 'default-entry', ) const defaultEntryPaths = { - client: path.resolve(defaultEntryDir, 'client'), - server: path.resolve(defaultEntryDir, 'server'), - start: path.resolve(defaultEntryDir, 'start'), + client: path.resolve(defaultEntryDir, 'client.tsx'), + server: path.resolve(defaultEntryDir, 'server.ts'), + start: path.resolve(defaultEntryDir, 'start.ts'), } export function tanstackStart(