From f18a440d4385d00b36aa2fac89ef5563b71117e3 Mon Sep 17 00:00:00 2001 From: g-mero Date: Tue, 23 Dec 2025 11:42:22 +0800 Subject: [PATCH 1/3] fix: resolve path on windows --- packages/start/src/config/index.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/start/src/config/index.ts b/packages/start/src/config/index.ts index 2523f2b6d..4b1c82179 100644 --- a/packages/start/src/config/index.ts +++ b/packages/start/src/config/index.ts @@ -1,9 +1,9 @@ import { TanStackServerFnPlugin } from "@tanstack/server-functions-plugin"; import { defu } from "defu"; import { globSync } from "node:fs"; -import { extname, isAbsolute, join, normalize } from "node:path"; +import { extname, isAbsolute, join } from "node:path"; import { fileURLToPath } from "node:url"; -import { type PluginOption } from "vite"; +import { normalizePath, type PluginOption } from "vite"; import solid, { type Options as SolidOptions } from "vite-plugin-solid"; import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.ts"; @@ -126,8 +126,10 @@ export function solidStart(options?: SolidStartOptions): Array { define: { "import.meta.env.MANIFEST": `globalThis.MANIFEST`, "import.meta.env.START_SSR": JSON.stringify(start.ssr), - "import.meta.env.START_APP_ENTRY": `"${appEntryPath}"`, - "import.meta.env.START_CLIENT_ENTRY": `"${handlers.client}"`, + // Use JSON.stringify so backslashes on Windows are escaped and + // esbuild receives a valid JS string literal for the define value + "import.meta.env.START_APP_ENTRY": JSON.stringify(appEntryPath), + "import.meta.env.START_CLIENT_ENTRY": JSON.stringify(handlers.client), "import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay), }, builder: { @@ -173,8 +175,8 @@ export function solidStart(options?: SolidStartOptions): Array { envConsumer: "client", envName: VITE_ENVIRONMENTS.client, getRuntimeCode: () => - `import { createServerReference } from "${normalize( - fileURLToPath(new URL("../server/server-runtime", import.meta.url)), + `import { createServerReference } from "${normalizePath( + fileURLToPath(new URL("../server/server-runtime", import.meta.url)) )}"`, replacer: opts => `createServerReference('${opts.functionId}')`, }, @@ -182,8 +184,8 @@ export function solidStart(options?: SolidStartOptions): Array { envConsumer: "server", envName: VITE_ENVIRONMENTS.server, getRuntimeCode: () => - `import { createServerReference } from '${normalize( - fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)), + `import { createServerReference } from '${normalizePath( + fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)) )}'`, replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`, }, @@ -191,8 +193,8 @@ export function solidStart(options?: SolidStartOptions): Array { provider: { envName: VITE_ENVIRONMENTS.server, getRuntimeCode: () => - `import { createServerReference } from '${normalize( - fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)), + `import { createServerReference } from '${normalizePath( + fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)) )}'`, replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`, }, From 509e3d22bd494c99c8b1a0154f29927ad65e95ff Mon Sep 17 00:00:00 2001 From: g-mero Date: Wed, 24 Dec 2025 12:55:57 +0800 Subject: [PATCH 2/3] fix: cleanPath compatibility with windows --- packages/start/src/config/fs-routes/router.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/start/src/config/fs-routes/router.ts b/packages/start/src/config/fs-routes/router.ts index bfc66c96b..1a8b07a07 100644 --- a/packages/start/src/config/fs-routes/router.ts +++ b/packages/start/src/config/fs-routes/router.ts @@ -1,5 +1,4 @@ -import { init } from "es-module-lexer"; -import { parse } from "es-module-lexer"; +import { init, parse } from "es-module-lexer"; import esbuild from "esbuild"; import fg from "fast-glob"; import fs from "fs"; @@ -19,6 +18,9 @@ type Route = { path: string } & Record; export function cleanPath(src: string, config: FileSystemRouterConfig) { return src .slice(config.dir.length) + // replace double backslashes with single forward slashes (windows compatibility) + .replace(/\\+/g, "/") + .replace(/\/\/+/, "/") .replace(new RegExp(`\.(${(config.extensions ?? []).join("|")})$`), ""); } From a527e892043ccb91057721c444a6207ff1a2469d Mon Sep 17 00:00:00 2001 From: g-mero Date: Wed, 24 Dec 2025 13:49:05 +0800 Subject: [PATCH 3/3] fix: rollback cleanPath changes, and fix windows compatibility by replacing `normalize` with `normalizePath` --- packages/start/src/config/fs-routes/router.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/start/src/config/fs-routes/router.ts b/packages/start/src/config/fs-routes/router.ts index 1a8b07a07..894237b02 100644 --- a/packages/start/src/config/fs-routes/router.ts +++ b/packages/start/src/config/fs-routes/router.ts @@ -6,7 +6,7 @@ import micromatch from "micromatch"; import { posix } from "path"; import { pathToRegexp } from "path-to-regexp"; -import { normalize } from "node:path"; +import { normalizePath } from "vite"; export { pathToRegexp }; @@ -18,9 +18,6 @@ type Route = { path: string } & Record; export function cleanPath(src: string, config: FileSystemRouterConfig) { return src .slice(config.dir.length) - // replace double backslashes with single forward slashes (windows compatibility) - .replace(/\\+/g, "/") - .replace(/\/\/+/, "/") .replace(new RegExp(`\.(${(config.extensions ?? []).join("|")})$`), ""); } @@ -106,7 +103,7 @@ export class BaseFileSystemRouter extends EventTarget { } async addRoute(src: string) { - src = normalize(src); + src = normalizePath(src); if (this.isRoute(src)) { try { const route = this.toRoute(src); @@ -132,7 +129,7 @@ export class BaseFileSystemRouter extends EventTarget { } async updateRoute(src: string) { - src = normalize(src); + src = normalizePath(src); if (this.isRoute(src)) { try { const route = this.toRoute(src); @@ -148,7 +145,7 @@ export class BaseFileSystemRouter extends EventTarget { } removeRoute(src: string) { - src = normalize(src); + src = normalizePath(src); if (this.isRoute(src)) { const path = this.toPath(src); if (path === undefined) {