cloudflare / cloudflare/workers-sdk

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

Open
#14,869 1 comment 0 reactions 0 assignees View on GitHub
package:vite-plugin
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
186

Description

### What versions & operating system are you using?

```sh
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

```shell
$ 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. (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.
```

Contributor guide

Open the contributing guide

Research direction

Start with the linked minimal reproduction and the Vite and Vitest configurations that use @cloudflare/vite-plugin with browser mode. Run `vitest --run` and trace the startup failure through `workers/runner-worker/index.js`, especially `runInRunnerObject` and `getWorkerEntryExportTypes`. Done means Vitest browser mode starts without the reported `module is not defined` or related startup error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.