Skip to content

vp test fails with @cloudflare/vitest-plugin while vitest run passes (1.8.0, again after #1076) #3619

In review

Description

@gxcsoccer

Describe the bug

With @cloudflare/vitest-plugin (the renamed @cloudflare/vitest-pool-workers), vp test run fails before any test is collected, while vitest run in the same project, with the same config, passes. This looks like #1076 again, on vite-plus 1.8.0 and Vitest 5.1.1, with a fresh lockfile.

Error: Vitest failed to find the current suite. One of the following is possible:
- "vitest" is imported directly without running "vitest" command
...
 Test Files  1 failed (1)
      Tests  no tests

It fails the same way whether the test imports from vite-plus/test or from vitest. In a larger project the error was Vitest failed to find the runner and TypeError: Cannot read properties of undefined (reading 'config'), as in #1076.

After a fresh pnpm install there are two copies of vitest@5.1.1 in node_modules/.pnpm, differing only in peers (one with vite@8.4.0, one with @voidzero-dev/vite-plus-core). My guess is that the plugin's worker gets one and vp's runner the other. pnpm dedupe does not change that.

Reproduction

Six small files, all inline below (no repository).

Steps to reproduce

package.json

{
  "name": "vp-cloudflare-vitest-plugin-repro",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "vp test run",
    "test:vitest": "vitest run"
  },
  "devDependencies": {
    "@cloudflare/vitest-plugin": "1.8.4",
    "@cloudflare/workers-types": "^5.20261008.1",
    "typescript": "^6.0.3",
    "vite-plus": "1.8.0",
    "vitest": "5.1.1",
    "wrangler": "^4.148.0"
  },
  "packageManager": "pnpm@10.26.2"
}

pnpm-workspace.yaml (what vp migrate writes)

catalog:
  vite: npm:@voidzero-dev/vite-plus-core@8.3.8001
  vitest: 5.1.1
  vite-plus: 1.8.0
overrides:
  vite@*: 'catalog:'
  vitest@*: 'catalog:'
peerDependencyRules:
  allowAny:
    - vitest
  allowedVersions:
    vitest: '*'

vite.config.ts

import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineConfig } from "vite-plus";

export default defineConfig({
  plugins: [cloudflareTest({ wrangler: { configPath: "./wrangler.jsonc" } })],
  test: { include: ["test/**/*.test.ts"] },
});

wrangler.jsonc

{ "name": "repro", "main": "src/index.ts", "compatibility_date": "2026-11-01" }

src/index.ts

export default {
  async fetch(): Promise<Response> {
    return Response.json({ ok: true });
  },
};

test/index.test.ts

import { exports } from "cloudflare:workers";
import { expect, test } from "vite-plus/test";

test("responds", async () => {
  const response = await (exports as any).default.fetch("https://example.com/");
  expect(await response.json()).toEqual({ ok: true });
});

Then:

pnpm install
pnpm exec vp test run   # fails: no tests
pnpm exec vitest run    # passes: 1 test

System Info

vp v1.8.0
  vite      v8.3.8
  rolldown  v1.2.19
  vitest    v5.1.1
@cloudflare/vitest-plugin 1.8.4
wrangler 4.169.1
pnpm 10.26.2
macOS (arm64), Node 22.23.2 (also on 25.9.0)

Used Package Manager

pnpm

Logs

 FAIL  test/index.test.ts [ test/index.test.ts ]
Error: Vitest failed to find the current suite. One of the following is possible:
- "vitest" is imported directly without running "vitest" command
- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)
- "vitest" is imported inside Vite / Vitest config file
- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues

 ❯ test/index.test.ts:5:31

 Test Files  1 failed (1)
      Tests  no tests
$ ls node_modules/.pnpm | grep '^vitest@'
vitest@5.1.1_@vitest+browser-preview@5.1.1_@vitest+ui@5.1.1_vite@8.4.0_esbuild@0.28.2_
vitest@5.1.1_@vitest+browser-preview@5.1.1_@vitest+ui@5.1.1_vitest@5.1.1__@voidzero-dev_59ab306aace139a99f40a74aba5aacf8

Activity

  1. gxcsoccer commented on Nov 30, 2026

    @gxcsoccer
    Author

    I found the cause. It is in the dependency setup that vp migrate writes, not in the Cloudflare plugin.

    • pnpm-workspace.yaml has overrides: vite@*: npm:@voidzero-dev/vite-plus-core@8.3.8001.

    • The project has no direct vite dependency. vitest's vite peer is auto-installed by pnpm, and the override does not apply to it, so the lockfile has the real vite@8.4.0:

      overrides:
        vite@*: npm:@voidzero-dev/vite-plus-core@8.3.8001
      ...
        vite@8.4.0:
          resolution: {integrity: sha512-X2nU...}
      
    • That gives two vitest@5.1.1 instances: the project's (and @cloudflare/vitest-plugin's) peers vite@8.4.0, and vite-plus's peers @voidzero-dev/vite-plus-core:

      node_modules/vitest                                   -> vitest@5.1.1_..._vite@8.4.0_esbuild@0.28.2_
      @cloudflare/vitest-plugin's vitest                    -> vitest@5.1.1_..._vite@8.4.0_esbuild@0.28.2_
      vite-plus's vitest                                    -> vitest@5.1.1_..._vitest@5.1.1__@voidzero-dev_59ab306a...
      

      vp test sets the runner up in vite-plus's instance. Inside workerd, the plugin resolves vitest relative to the test file and gets the project's instance, which has no runner.

    Workaround, verified in the repro above: declare vite from the catalog so that the override applies:

    "devDependencies": {
      "vite": "catalog:",
      "vitest": "catalog:",
      "vite-plus": "catalog:"
    }

    After rm -rf node_modules pnpm-lock.yaml && pnpm install there is one vitest@5.1.1, and both vp test run and vitest run pass.

    Possible fix: when vp migrate sees that a package uses Vitest but has no direct vite dependency, it could add vite: catalog:. vitePeerDependencyRuleRequired in packages/cli/src/migration/migrator/shared.ts already covers how pnpm applies the alias override to peers, but not this case, where the peer is auto-installed. Resolving vitest from the running Vitest (ctx.distPath) in the Cloudflare plugin would also avoid the split, but the duplicate install looks like the root cause.

  2. voidzero-bot commented on Nov 30, 2026

    @voidzero-bot
    Contributor

    Triage failed unexpectedly (attempt 1 of 3).

    Run: https://github.com/voidzero-dev/vite-plus/actions/runs/46349739084

    I can retry if a new comment provides more information or asks me to try again.

    Error:

    [flue] skill("triage") failed: terminated
    
  3. added theissue type on Nov 30, 2026
  4. added
    bug
    and removed on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugtriage: failed

Type

Fields

Priority

None yet

Effort

None yet

Target date

None yet

Start date

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions