vite icon indicating copy to clipboard operation
vite copied to clipboard

CachedFsUtils cause issue on Windows

Open Maxim-Mazurok opened this issue 1 year ago • 1 comments

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

  1. Use Windows
  2. 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
  3. Clone https://github.com/Maxim-Mazurok/vite-cache-fs-repro
  4. npm ci
  5. npm run build - should build into existing bin folder (included in repo) instead of Bin
  6. npm run preview
  7. 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

Maxim-Mazurok avatar Jul 31 '24 08:07 Maxim-Mazurok

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
    }
  }
});

Maxim-Mazurok avatar Jul 31 '24 08:07 Maxim-Mazurok

Closing as server.fs.cachedChecks is removed and works as false since Vite 6.0.0.

sapphi-red avatar Dec 02 '24 07:12 sapphi-red

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.

Maxim-Mazurok avatar Dec 02 '24 10:12 Maxim-Mazurok

Thanks for reporting back @Maxim-Mazurok. My take is that this is expected in a Windows/NTFS system.

patak-dev avatar Dec 02 '24 12:12 patak-dev