#3895·fresh

Dev server fails with ENOENT errors when optimizeDeps enabled in Vite config

Author: mryall-mawsonCreated Jul 30, 2026Updated Jul 30, 2026

Enabling optimizeDeps in vite.config.ts makes the Fresh dev server return 500 for every request.

With optimizeDeps enabled, the Deno loader plugin receives a module id carrying Vite's ?v=<hash> suffix and passes it to path.toFileUrl(), which percent-encodes the ? into the filename, which throws an exception because the file cannot be found:

[vite] Internal server error: Unable to load
  /…/[email protected]/…/preact/debug/dist/debug.module.js?v=ff8da874:
  ENOENT: no such file or directory, open
  '/…/[email protected]/…/preact/debug/dist/debug.module.js?v=ff8da874'

Both environments are affected — client and environments.ssr fail identically, on the .module.js and .mjs builds respectively.

The failing module is not the one being optimized: adding preact to optimizeDeps produces the error for preact/debug. Vite versions dependency ids whether or not it pre-bundles them, so excluding one module just moves the error to the next.

Reproduction

See https://github.com/mryall-mawson/fresh-vite-loader-repro

app/ is an unmodified deno run -Ar jsr:@fresh/init@^2 scaffold; the only edit is vite.config.ts, switching optimizeDeps on from an env var:

./run.sh
without optimizeDeps: HTTP 200
with optimizeDeps   : HTTP 500

repro.ts in the same repo shows the defect with no Vite or Fresh involved.

Expected behaviour

The page renders with optimizeDeps enabled.

Versions

@fresh/core 2.3.3, @fresh/plugin-vite 1.1.2, vite 7.3.6, deno 2.9.4

Cause

packages/plugin-vite/src/plugins/deno.ts:220

javascript
const url = path.toFileUrl(id);
const result = await loader.load(url.href, meta.type);