diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 4b1b0e81173917..9bc07e7f1f422b 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -536,7 +536,13 @@ function tryResolveFile( skipPackageJson?: boolean, skipTsExtension?: boolean, ): string | undefined { - const stat = fs.statSync(file, { throwIfNoEntry: false }) + let stat: fs.Stats | undefined + try { + stat = fs.statSync(file, { throwIfNoEntry: false }) + } catch { + return + } + if (stat) { if (!stat.isDirectory()) { return getRealPath(file, options.preserveSymlinks) + postfix