Skip to content
Latchkey

Storybook test-runner "Cannot connect to Storybook at http://127.0.0.1:6006" in CI

The test-runner tried to open the Storybook URL and the connection was refused or returned nothing usable. Either nothing is listening on that port, or Storybook is served on a different host/port than the runner expects.

What this error means

The runner fails with "Cannot connect to Storybook at http://127.0.0.1:6006" or "connect ECONNREFUSED 127.0.0.1:6006".

test-runner
Cannot connect to Storybook at http://127.0.0.1:6006.
connect ECONNREFUSED 127.0.0.1:6006

Common causes

Storybook served on a different port

The static server or storybook dev uses a port other than 6006, but the runner defaults to 6006.

The server exited before the runner connected

A background Storybook process crashed or was not kept alive, so the port is closed when the runner tries.

How to fix it

Align the served port with the runner URL

  1. Serve Storybook on a known port.
  2. Pass the same URL to the runner with --url.
  3. Confirm the server stays up for the test duration.
Terminal
npx http-server storybook-static --port 6006 --silent &
npx wait-on tcp:127.0.0.1:6006
npx test-storybook --url http://127.0.0.1:6006

Bind the server to the address the runner uses

If the runner uses 127.0.0.1, do not serve only on localhost/IPv6; bind explicitly so the address matches.

Terminal
npx http-server storybook-static -a 127.0.0.1 --port 6006

How to prevent it

  • Serve and test on the same explicit host and port.
  • Keep the Storybook server alive for the whole test run with concurrently.
  • Wait for the port before starting the runner.

Frequently asked questions

What causes ""Cannot connect to Storybook""?
The static server or storybook dev uses a port other than 6006, but the runner defaults to 6006.
How do I fix "Cannot connect to Storybook"?
Align the served port with the runner URL

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card