Skip to content

[vite-plugin] Vitest in Browser Mode errors on startup with Cloudflare Vite plugin #14869

Description

@jeremy-code

What versions & operating system are you using?

System:
  OS: macOS 26.5.2
  CPU: (8) arm64 Apple M1
  Memory: 142.52 MB / 8.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 24.18.0 - /Users/jeremy/.nodenv/versions/24.18.0/bin/node
  Yarn: 1.22.22 - /opt/homebrew/bin/yarn
  npm: 11.16.0 - /Users/jeremy/.nodenv/versions/24.18.0/bin/npm
  pnpm: 11.17.0 - /opt/homebrew/bin/pnpm
  Deno: 2.9.3 - /opt/homebrew/bin/deno
npmPackages:
  @cloudflare/vite-plugin: ^1.47.0 => 1.47.0 
  wrangler: ^4.114.0 => 4.114.0

Please provide a link to a minimal reproduction

https://github.com/jeremy-code/cloudflare-vite-vitest

Describe the Bug

Steps to reproduce

  1. Create Vite config with @cloudflare/vite-plugin
  2. Create Vitest config extending Vite config using Vitest browser mode
  3. Attempt to run vitest

This only occurs in browser mode. In the minimal reproduction, the error logged is "module is not defined".

FWIW, though I could not reproduce it, on a different project, I receive the error: TypeError: Cannot read properties of undefined (reading 'wrapDynamicImport') with the same error stack. See also: withastro/astro#16275, vitest-dev/vitest#10319, sveltejs/kit#14149

Please provide any relevant error logs

$ vitest --run

⎯⎯⎯⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯⎯⎯⎯⎯
ReferenceError: module is not defined
    at runInRunnerObject (workers/runner-worker/index.js:107:3)
    at getWorkerEntryExportTypes (workers/runner-worker/index.js:246:24)
    at null.<anonymous> (workers/runner-worker/index.js:350:37)
    at maybeCaptureError (workers/runner-worker/index.js:51:10) {
  [cause]: undefined
}



[ELIFECYCLE] Test failed. See above for more details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    package:vite-pluginRelating to the `@cloudflare/vite-plugin` package

    Type

    Projects

    Status
    Untriaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions