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.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ 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)
What versions & operating system are you using?
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
resolve.externalin your Cloudflare Worker environments" withastro/astro#15310