Skip to content

[Bug] Browser mode: Cannot convert a Symbol value to a string in console.error #9377

@Suto-Michimasa

Description

@Suto-Michimasa

Describe the bug

In vitest 4.0.16 browser mode (@vitest/browser + Playwright runner), when console.error is called with an object containing Symbol properties, the baseFormat function in @vitest/utils throws a TypeError.

This commonly occurs with RTK Query error objects, which contain Symbol keys like Symbol() as internal markers. For example:

// RTK Query error object structure (simplified)
{
  status: "FETCH_ERROR",
  error: "...",
  [Symbol()]: "internal marker"  // This causes the crash
}

This is a regression from 4.0.15.

Reproduction

https://github.com/Suto-Michimasa/vitest-symbol-repro

Steps to reproduce

git clone https://github.com/Suto-Michimasa/vitest-symbol-repro
cd vitest-symbol-repro
pnpm install
pnpm test:browser

Stack trace

TypeError: Cannot convert a Symbol value to a string
    at baseFormat (@vitest/[email protected]/dist/display.js:700:15)
    at browserFormat (@vitest/[email protected]/dist/display.js:711:9)
    at processLog (__vitest_browser__/tester.js:1202:10)
    at console.error (__vitest_browser__/tester.js:1198:23)

Regression confirmation

Downgrading to 4.0.15 resolves the issue:

pnpm up [email protected] @vitest/[email protected] @vitest/[email protected]
pnpm test:browser  # passes

Expected behavior

  • Symbol properties should be safely handled during console output formatting (ignored or converted via String(symbol))
  • Tests should pass without TypeError

Actual behavior

  • Tests fail with TypeError: Cannot convert a Symbol value to a string
  • The browser runner crashes when formatting objects with Symbol keys

System Info

- vitest: 4.0.16
- @vitest/browser: 4.0.16
- @vitest/browser-playwright: 4.0.16
- playwright: 1.57.0
- Browser: Chromium (via Playwright)
- Node.js: 20+
- OS: macOS

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions