Skip to content

Browser mode fails with SyntaxError: Failed to construct 'WebSocket' #5382

@kossnocorp

Description

@kossnocorp

Describe the bug

After upgrading Vitest in the date-fns codebase ([email protected] -> [email protected] & @vitest/[email protected] -> @vitest/[email protected]) I started getting many of these errors:

SyntaxError: Failed to construct 'WebSocket': The URL 'ws://localhost:undefined/' is invalid.
❯ setupWebSocket /@vite/client:505:20
❯ fallback /@vite/client:484:22
❯ WebSocket.<anonymous> /@vite/client:520:13

As the result npx vitest run --browser hangs forever, even though the tests pass when I open it with --ui.

Reproduction

git clone [email protected]:date-fns/date-fns.git
cd date-fns
npm install
npm install -D @vitest/ui
npx vitest --browser --ui

It will open the browser where you can see the errors:

image

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
    Memory: 15.01 GB / 31.31 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.asdf/installs/nodejs/20.10.0/bin/node
    Yarn: 1.22.21 - ~/.asdf/installs/nodejs/20.10.0/bin/yarn
    npm: 10.2.3 - ~/.asdf/plugins/nodejs/shims/npm
    bun: 1.0.25 - ~/src/date-fns/date-fns/node_modules/.bin/bun
  Browsers:
    Chrome: 103.0.5060.114
  npmPackages:
    @vitest/browser: ^1.3.1 => 1.3.1 
    @vitest/coverage-v8: ^1.3.1 => 1.3.1 
    vitest: ^1.3.1 => 1.3.1

Used Package Manager

npm

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

    No type

    Projects

    Status

    Has plan

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions