Skip to content

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

Description

@mryall-mawson

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
  /…/preact@10.29.7/…/preact/debug/dist/debug.module.js?v=ff8da874:
  ENOENT: no such file or directory, open
  '/…/preact@10.29.7/…/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

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

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions