[BUG]
Platform
GitHub Actions runners (ubuntu-latest, windows-latest, macos-latest); also reproduced locally on Linux with bun 1.3.11 / moon 2.3.3
Browser
N/A — this is a CI / build-tooling bug, not browser-related
Current Behavior
moon ci fails on every push and pull request to main.
The test task in apps/web runs vitest run, which reuses vite.config.ts and therefore loads the Cloudflare Vite plugin (cloudflare({ viteEnvironment: { name: 'ssr' } })). That plugin configures a Worker SSR environment that is incompatible with Vitest, so Vitest throws during config resolution, before any test is collected. Because .github/workflows/bun-ci.yml runs moon ci, the whole pipeline is red.
Error:
⎯ Startup Error ⎯
Error: The following environment options are incompatible with the Cloudflare Vite plugin:
- "ssr" environment: `resolve.external`: [ ... node builtins ... ]
To resolve this issue, avoid setting `resolve.external` in your Cloudflare Worker environments.
at validateWorkerEnvironmentOptions (@cloudflare/vite-plugin/dist/index.mjs)
error: script "test" exited with code 1
Expected Behavior
moon ci passes. The web test task should run under an environment compatible with the app (jsdom) and succeed — including when there are no test files yet, instead of crashing the whole pipeline.
Recurrence Probability
Always
Steps To Reproduce
- cd apps/web
- bun install
- bun run test # this is what
moon ciruns for apps/web:test - Vitest crashes at startup and exits with code 1
Anything else?
Root cause: Vitest reuses vite.config.ts, which registers the Cloudflare Vite plugin; its Worker SSR environment conflicts with Vitest's own environment setup. Separately, there are no test files yet, so even without the plugin vitest run would exit non-zero ("No test files found").
Proposed fix: give Vitest a dedicated apps/web/vitest.config.ts isolated from the Cloudflare plugin, running in jsdom with passWithNoTests: true. After that, bun run test exits 0 and moon ci is green. jsdom and @testing-library/react are already devDependencies.
Minor related fix: apps/api/moon.yml declares outputs: ['dist'] but wrangler deploy --dry-run produces no dist; adding --outdir dist makes the declared output truthful.
I already have both fixes implemented and verified locally, and can open a small focused PR once a maintainer approves, per the contribution policy.
hellooo ??!
Can I help u in something
Thank you, go ahead
Root Cause & Working Fix
The issue occurs because Vitest reuses vite.config.ts, where @cloudflare/vite-plugin is registered with { viteEnvironment: { name: 'ssr' } }. During test runner startup, Vitest populates resolve.external in SSR mode with standard Node built-ins, which triggers the Cloudflare Vite plugin's environment validation assertion:
Error: The following environment options are incompatible with the Cloudflare Vite plugin:
- "ssr" environment: `resolve.external`: [...]
To resolve this issue, avoid setting `resolve.external` in your Cloudflare Worker environments.
Additionally, Vitest exits non-zero when no test files match if --passWithNoTests is omitted.
Solution
-
Conditionally exclude Cloudflare plugin during test runs (
apps/web/vite.config.ts): Vitest automatically setsprocess.env.VITEST = 'true'. We can gate the plugin so it only initializes during dev/build/preview and is omitted when running under Vitest:const isTest = Boolean(process.env.VITEST) const config = defineConfig({ resolve: { tsconfigPaths: true }, plugins: [ devtools(), !isTest && cloudflare({ viteEnvironment: { name: 'ssr' } }), tailwindcss(), tanstackStart(), viteReact(), ].filter(Boolean), }) -
Allow clean execution when test files are pending (
apps/web/package.json):"test": "vitest run --passWithNoTests"
Verification
bun run testinapps/web: exits 0 cleanly without startup crash.moon run web:test: exits 0 cleanly.- Normal build
bun run build: continues to initialize Cloudflare SSR environment and buildsdist/server/wrangler.jsonwithout regressions.
Branch: fix/web-vitest-cloudflare-plugin-conflict
Commit: af79b1c1
Since direct PR creation is currently restricted to collaborators, maintainers can cherry-pick this fix directly.