OpenCut icon indicating copy to clipboard operation
OpenCut copied to clipboard

[BUG]

Open LeminEly opened this issue 5 months ago • 3 comments

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

  1. cd apps/web
  2. bun install
  3. bun run test # this is what moon ci runs for apps/web:test
  4. 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.

LeminEly avatar Jul 01 '26 09:07 LeminEly

hellooo ??!

LeminEly avatar Jul 12 '26 20:07 LeminEly

Can I help u in something

Thank you, go ahead

LeminEly avatar Jul 13 '26 13:07 LeminEly

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

  1. Conditionally exclude Cloudflare plugin during test runs (apps/web/vite.config.ts): Vitest automatically sets process.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),
    })
    
  2. Allow clean execution when test files are pending (apps/web/package.json):

    "test": "vitest run --passWithNoTests"
    

Verification

  • bun run test in apps/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 builds dist/server/wrangler.json without 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.

killer1panda avatar Sep 08 '26 08:09 killer1panda