diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index b614da2696318c..e48db640fe2280 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -537,7 +537,14 @@ export function writeFile( export function isFileReadable(filename: string): boolean { try { + // The "throwIfNoEntry" is a performance optimization for cases where the file does not exist + if (!fs.statSync(filename, { throwIfNoEntry: false })) { + return false + } + + // Check if current process has read permission to the file fs.accessSync(filename, fs.constants.R_OK) + return true } catch { return false