Skip to content

Default readFile returns directory contents as module source on macOS (/dev), crashing Vite dev server #550

Closed

Description

@christowiz

Describe the bug

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:

  1. Vite SPA with sourcemaps() (no options) in plugins
  2. Add a client-side route at /dev
  3. 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.

Minimal repro: https://github.com/christowiz/rollup-plugin-sourcemaps2-devfs-repro

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.ts load 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.ts load 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

  1. added
    bug
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions