Skip to content

[vite-plugin] Vitest errors on startup with Cloudflare Vite plugin #14215

Description

@jeremy-code

What versions & operating system are you using?

System:
  OS: macOS 26.2
  CPU: (8) arm64 Apple M1
  Memory: 162.63 MB / 8.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 24.9.0 - /Users/jeremy/.nodenv/versions/24.9.0/bin/node
  Yarn: 1.22.22 - /opt/homebrew/bin/yarn
  npm: 11.6.0 - /Users/jeremy/.nodenv/versions/24.9.0/bin/npm
  pnpm: 10.33.2 - /opt/homebrew/bin/pnpm
  Deno: 2.8.1 - /opt/homebrew/bin/deno
npmPackages:
  @cloudflare/vite-plugin: ^1.40.0 => 1.40.0 
  wrangler: ^4.98.0 => 4.98.0

Please provide a link to a minimal reproduction

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

Describe the Bug

If vitest is ran when the "@cloudflare/vite-plugin" vite plugin is included, it will error claiming that resolve.external is incompatible with the Cloudflare Vite plugin.

Including cloudflareTest from "@cloudflare/vitest-pool-workers" does not seem to solve the issue.

The relevant code seems to be here in the "vitest:environments-module-runner": https://github.com/vitest-dev/vitest/blob/bdd985433e31b7e792483dab8f07a6832960fa55/packages/vitest/src/node/plugins/runnerTransform.ts#L99-L103, which adds the list of node built-in modules to config environments not named vitest_vm or vitest.

Please provide any relevant error logs

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: The following environment options are incompatible with the Cloudflare Vite plugin:
        - "cloudflare_vite_vitest" environment: `resolve.external`: ["_http_agent","_http_client","_http_common","_http_incoming","_http_outgoing","_http_server","_stream_duplex","_stream_passthrough","_stream_readable","_stream_transform","_stream_wrap","_stream_writable","_tls_common","_tls_wrap","assert","assert/strict","async_hooks","buffer","child_process","cluster","console","constants","crypto","dgram","diagnostics_channel","dns","dns/promises","domain","events","fs","fs/promises","http","http2","https","inspector","inspector/promises","module","net","os","path","path/posix","path/win32","perf_hooks","process","punycode","querystring","readline","readline/promises","repl","stream","stream/consumers","stream/promises","stream/web","string_decoder","sys","timers","timers/promises","tls","trace_events","tty","url","util","util/types","v8","vm","wasi","worker_threads","zlib","node:sea","node:sqlite","node:test","node:test/reporters","node:_http_agent","node:_http_client","node:_http_common","node:_http_incoming","node:_http_outgoing","node:_http_server","node:_stream_duplex","node:_stream_passthrough","node:_stream_readable","node:_stream_transform","node:_stream_wrap","node:_stream_writable","node:_tls_common","node:_tls_wrap","node:assert","node:assert/strict","node:async_hooks","node:buffer","node:child_process","node:cluster","node:console","node:constants","node:crypto","node:dgram","node:diagnostics_channel","node:dns","node:dns/promises","node:domain","node:events","node:fs","node:fs/promises","node:http","node:http2","node:https","node:inspector","node:inspector/promises","node:module","node:net","node:os","node:path","node:path/posix","node:path/win32","node:perf_hooks","node:process","node:punycode","node:querystring","node:readline","node:readline/promises","node:repl","node:stream","node:stream/consumers","node:stream/promises","node:stream/web","node:string_decoder","node:sys","node:timers","node:timers/promises","node:tls","node:trace_events","node:tty","node:url","node:util","node:util/types","node:v8","node:vm","node:wasi","node:worker_threads","node:zlib","node:node:sea","node:node:sqlite","node:node:test","node:node:test/reporters"]
To resolve this issue, avoid setting `resolve.external` in your Cloudflare Worker environments.

    at validateWorkerEnvironmentOptions (file:///Users/jeremy/Github/cloudflare-vite-vitest/node_modules/.pnpm/@cloudflare+vite-plugin@1.40.0_vite@8.0.16_esbuild@0.27.3_jiti@2.7.0__workerd@1.20260603.1_wrangler@4.98.0/node_modules/@cloudflare/vite-plugin/dist/index.mjs:51536:9)
    at BasicMinimalPluginContext.configResolved (file:///Users/jeremy/Github/cloudflare-vite-vitest/node_modules/.pnpm/@cloudflare+vite-plugin@1.40.0_vite@8.0.16_esbuild@0.27.3_jiti@2.7.0__workerd@1.20260603.1_wrangler@4.98.0/node_modules/@cloudflare/vite-plugin/dist/index.mjs:51577:53)
    at file:///Users/jeremy/Github/cloudflare-vite-vitest/node_modules/.pnpm/vite@8.0.16_esbuild@0.27.3_jiti@2.7.0/node_modules/vite/dist/node/chunks/node.js:34748:87
    at Array.map (<anonymous>)
    at resolveConfig (file:///Users/jeremy/Github/cloudflare-vite-vitest/node_modules/.pnpm/vite@8.0.16_esbuild@0.27.3_jiti@2.7.0/node_modules/vite/dist/node/chunks/node.js:34748:68)
    at async _createServer (file:///Users/jeremy/Github/cloudflare-vite-vitest/node_modules/.pnpm/vite@8.0.16_esbuild@0.27.3_jiti@2.7.0/node_modules/vite/dist/node/chunks/node.js:26197:65)
    at async createViteServer (file:///Users/jeremy/Github/cloudflare-vite-vitest/node_modules/.pnpm/vitest@4.1.8_vite@8.0.16_esbuild@0.27.3_jiti@2.7.0_/node_modules/vitest/dist/chunks/cli-api.BfdDOPPI.js:8819:17)
    at async createVitest (file:///Users/jeremy/Github/cloudflare-vite-vitest/node_modules/.pnpm/vitest@4.1.8_vite@8.0.16_esbuild@0.27.3_jiti@2.7.0_/node_modules/vitest/dist/chunks/cli-api.BfdDOPPI.js:14205:18)
    at async prepareVitest (file:///Users/jeremy/Github/cloudflare-vite-vitest/node_modules/.pnpm/vitest@4.1.8_vite@8.0.16_esbuild@0.27.3_jiti@2.7.0_/node_modules/vitest/dist/chunks/cli-api.BfdDOPPI.js:14572:14)
    at async startVitest (file:///Users/jeremy/Github/cloudflare-vite-vitest/node_modules/.pnpm/vitest@4.1.8_vite@8.0.16_esbuild@0.27.3_jiti@2.7.0_/node_modules/vitest/dist/chunks/cli-api.BfdDOPPI.js:14515:14)

The Vitest resolved config can be found here: https://github.com/jeremy-code/cloudflare-vite-vitest/blob/main/vitestResolvedConfig.json

Related issues

Metadata

Metadata

Assignees

Labels

awaiting-response:cloudflareAwaiting response from the workers-sdk maintainer teampackage:vite-pluginRelating to the `@cloudflare/vite-plugin` packagepackage:vitestRelating to the Workers Vitest integration

Type

No fields configured for Bug.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions