Skip to content

Conversation

@serhalp
Copy link
Member

@serhalp serhalp commented Nov 4, 2025

Problem

The plugin was passing the entire Vite project root to Netlify's static file handler, which caused it to stat() files in Vite's internal directories (e.g., node_modules/.vite/deps). On Windows, this creates file locks that prevent Vite from atomically renaming temporary dependency files during prebundling, resulting in EPERM errors when opening Sanity Studio or other apps that trigger Vite's dependency optimization.

Root Cause

When Netlify's static handler processes requests, it checks if files exist by calling stat() on potential paths. By including the entire project root in the static directories list, the handler was checking files in Vite's internal directories like node_modules/.vite/deps/*.js. On Windows, even a read-only stat() call can create a file handle that prevents Vite from renaming temporary files (e.g., deps_tmpdeps), causing the EPERM error.

Solution

The fix is to only include viteDevServer.config.publicDir in the static directories list, not the entire project root. This aligns with Vite's contract that only the public directory contains static assets that should be served verbatim, while everything else (including Vite's internal prebundles, virtual modules, etc.) is Vite's private implementation detail.

This change ensures Netlify's static handler never touches Vite's internal files, eliminating the file locking race condition on Windows while maintaining correct behavior for actual static assets.

Changes

  • Removed viteDevServer.config.root from the static directories list
  • Only include viteDevServer.config.publicDir (if it's a string) plus any user-supplied directories
  • Added comments explaining why we don't include the project root

Fixes #408

…oot from static directories

Previously, the plugin was passing the entire Vite project root to Netlify's
static file handler, which caused it to stat() files in Vite's internal
directories (e.g., node_modules/.vite/deps). On Windows, this creates file
locks that prevent Vite from atomically renaming temporary dependency files
during prebundling, resulting in EPERM errors when opening Sanity Studio or
other apps that trigger Vite's dependency optimization.

The fix is to only include viteDevServer.config.publicDir in the static
directories list, not the entire project root. This aligns with Vite's
contract that only the public directory contains static assets that should
be served verbatim, while everything else (including Vite's internal
prebundles, virtual modules, etc.) is Vite's private implementation detail.

This change ensures Netlify's static handler never touches Vite's internal
files, eliminating the file locking race condition on Windows while
maintaining correct behavior for actual static assets.

Fixes #408
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vite-plugin added to @astrojs/netlify causes sanity-astro Studio to fail on Windows dev

2 participants