CachedFsUtils cause issue on Windows
Describe the bug
TLDR, outDir was bla-bla/Bin, but vite built it into bla-bla/bin because it already existed, and then tried to to serve bla-bla/Bin for preview which failed.
I've had the following vite.config.ts:
const frontEndProjectRootDirectory = __dirname;
export default defineConfig({
build: {
outDir: join(frontEndProjectRootDirectory, "Bin", "Frontend", "public"),
emptyOutDir: true,
},
});
As you can see, it has Bin folder in the path, with capital B.
Now if I already have a bin folder (lowercase b) - vite will build into it instead of creating Bin folder, and later fail to use that folder during vite preview due to CachedFsUtils.
With the following change in https://github.com/vitejs/vite/blob/main/packages/vite/src/node/fsUtils.ts#L63, all works fine:
-fsUtils = createCachedFsUtils(config)
+fsUtils = commonFsUtils
Reproduction
https://github.com/Maxim-Mazurok/vite-cache-fs-repro
Steps to reproduce
- Use Windows
- Make sure case sensitivity is disabled for the path you'll be testing https://learn.microsoft.com/en-us/windows/wsl/case-sensitivity#modify-case-sensitivity
- Clone https://github.com/Maxim-Mazurok/vite-cache-fs-repro
npm cinpm run build- should build into existingbinfolder (included in repo) instead ofBinnpm run preview- Visit preview URL, it should return 404 (because it tries to server "Bin" but there's only "bin")
System Info
System:
OS: Windows 11 10.0.22631
CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900H
Memory: 30.63 GB / 63.68 GB
Binaries:
Node: 18.14.1 - ~\AppData\Local\nvs\default\node.EXE
npm: 9.3.1 - ~\AppData\Local\nvs\default\npm.CMD
Browsers:
Edge: Chromium (126.0.2592.102)
Internet Explorer: 11.0.22621.3527
npmPackages:
vite: ^5.3.4 => 5.3.5
Used Package Manager
npm
Logs
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Related to #15279
A workaround is to disable server.fs.cachedChecks in vite config:
import { defineConfig } from "vite";
import path from "path";
export default defineConfig({
build: {
outDir: path.join(__dirname, "Bin"),
emptyOutDir: true,
},
server: {
fs: {
cachedChecks: false
}
}
});
Closing as server.fs.cachedChecks is removed and works as false since Vite 6.0.0.
Testing v6.0.2, I can confirm that one of the issues is resolved - there will be no 404 after taking reproduction steps.
However, it will still build into lowercase bin folder if it already exists instead of deleting it and creating uppercase Bin folder as per config. This could be just a Windows/NTFS thing tho, maybe not much that can/should be done on vite side, up to you to decide.
Thanks for reporting back @Maxim-Mazurok. My take is that this is expected in a Windows/NTFS system.