Skip to content

Failed to run browser mode with Vitest #9242

@trofe-doorloop

Description

@trofe-doorloop

Describe the bug

I try to use browser mode testing user vitest, with version 4.0.15.

I configured vitest.config.ts file with:

import { defineConfig } from "vitest/config";
import tsconfigPaths from "vite-tsconfig-paths";
import { playwright } from "@vitest/browser-playwright";

const config = defineConfig({
  test: {
    projects: [
      {
        plugins: [
          tsconfigPaths({ projects: ["./tsconfig.paths.json", "../../tsconfig.base.json"], ignoreConfigErrors: true })
        ],
        test: {
          name: "Components & Hooks Unit Tests",
          include: ["src/**/tests/*.test.tsx", "src/**/tests/use-*.test.ts"],
          restoreMocks: true,
          environment: "jsdom",
          browser: {
            provider: playwright(),
            enabled: true,
            instances: [{ browser: "chromium" }],
            headless: true
          }
        }
      }
    ]
  }
});

export default config;

I followed the manual installation guide, https://vitest.dev/guide/browser/#manual-installation, and I'm using Playwright.

When I run vitest --run -c ./vitest.config.ts I get an error:

file:/node_modules/.pnpm/@vitest+browser@4.0.15_msw@2.10.5_@types+node@24.3.0_typescript@5.9.2__vite@7.1.12_@types+nod_nsppi3d66lnza46vhfuubbygma/node_modules/@vitest/browser/dist/index.js:2947
                        const state = project.browser.state;
                                                      ^

TypeError: Cannot read properties of undefined (reading 'state')

Can anyone tell why?

I checked my listed dependencies, all of them are using the same version 4.0.15.

I only run this dummy test:
import { describe, it, expect } from "vitest";

describe("TEST", () => {
it("TEST", () => {
expect(true).toBe(true);
});
});

And still get the error.

Reproduction

Above, and simple test.

System Info

Described above

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: browserIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions