Normalize internal paths to forward slashes for Windows support
#1,605 创建于 2026年5月26日
仓库指标
- Star
- (8,120 star)
- PR 合并指标
- (平均合并 1天 1小时) (30 天内合并 462 个 PR)
描述
Background
Vite normalizes all internal paths to forward slashes. On Windows, Node.js APIs (path.join, path.relative, fs.glob, etc.) return backslash paths. When vinext stores or compares these paths without normalization, things break — cache misses, failed route lookups, wrong startsWith/endsWith results, etc.
#1578 fixed the first case (StaticFileCache). #1604 extracted the fix into a reusable toSlash() utility in utils/path.ts. The same problem exists in other parts of the codebase.
Known affected areas
- Routing —
pagePath,layoutPath,errorPathfromapp-route-graph.tsare OS-native paths. Downstream forward-slash comparisons silently mismatch on Windows. - File scanner —
scanWithExtensionsyieldsfs.globresults which use backslashes on Windows. - Entry generators —
entries/files applynormalizePathSeparators()per-callsite; should migrate to the sharedutils/path.ts. - Build & deploy —
path.relative()in prerender output, asset prefix, deploy packaging. - Tests — Hardcoded forward-slash assertions and NTFS-illegal fixture filenames (
*,:) cause failures on Windows.
Proposal
-
Normalize at filesystem boundaries — apply
toSlash()whereverpath.join,path.relative, orfs.globproduces a path for internal use (#1604 provides the utility). For constructing internal-only paths that never touch the OS filesystem, preferpath.posix.jointo produce forward slashes directly without a normalize step. -
Add Windows CI on
mainonly — catch regressions post-merge without blocking the current fast-paced PR workflow.
References
- #1578 —
StaticFileCacheinline fix - #1604 —
utils/path.ts(slash/toSlash)