You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Default readFile returns directory contents as module source on macOS (/dev), crashing Vite dev server #550
The plugin's load hook treats anything that passes the include/exclude filter as a readable source file. With no options, the filter admits every id. If the id is a directory the default readFile still calls fs.readFile. On most filesystems that fails with EISDIR and the hook returns null harmlessly, but macOS devfs permits read() on the /dev directory, so the call succeeds and returns about 6.7 KB of raw directory records. The hook returns those bytes as module source and calls this.addWatchFile('/dev').
To Reproduce
Steps to reproduce the behavior:
Vite SPA with sourcemaps() (no options) in plugins
Add a client-side route at /dev
Run vite on macOS and hard-navigate to http://localhost:5173/dev (type the URL or refresh)
Vite classifies the extensionless path as a JS module request and its transform middleware runs before the SPA HTML fallback, so /dev reaches load as the module id.
Result: HTTP 500 content contains invalid JS syntax from vite:import-analysis, then the process exits with EBADF: bad file descriptor, lstat '/dev/fd/N' because Chokidar walks /dev/fd/* and Vite's watcher has no error listener.
Originally bisected on Vite 5.4.17: bare Vite serves /dev fine; enabling sourcemaps() alone reproduces the crash. Confirmed with the minimal repro on Vite 5.4.21, 6.4.4 and 7.1.7, the current 5.x and 6.x releases and the last 7.x before vitejs/vite#20866 (7.1.8) made browser navigations bypass the transform middleware. From Vite 8.3.2, vitejs/vite#23503 also stops the watcher error from exiting the process. The plugin still reads the directory, returns its bytes and watches /dev on every version. Newer Vite only hides the consequences.
Expected behavior load returns null for anything that is not a regular file and never calls addWatchFile for it.
Environment
Package 0.5.6 through 0.5.9 (logic unchanged across these, src/index.tsload hook). Node 22. macOS (Darwin 24.6). Vite 7.1.7 in the repro; also 5.4.21 and 6.4.4.
Package Version: Package 0.5.6 through 0.5.9 (logic unchanged across these, src/index.tsload hook).
Node.js Version: Node 22
Operating System: macOS Sequoia 15.8.1
Additional Environment Details: Vite 7.1.7 in the repro; also 5.4.21 and 6.4.4
Additional context
Fix proposed in the linked PR: #551
Activity